Skip to content

Instantly share code, notes, and snippets.

@Padhma
Created July 9, 2021 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Padhma/0e7a0b7cbbf88ce8276e6596ffe993f6 to your computer and use it in GitHub Desktop.
Save Padhma/0e7a0b7cbbf88ce8276e6596ffe993f6 to your computer and use it in GitHub Desktop.
# converting Star, Fork and Watch columns to numeric by replacing 'k' with 1000
github_df['Star'] = github_df['Star'].apply(lambda x: float(x.rstrip('k'))*1000 if x.endswith('k') else float(x))
github_df['Fork'] = github_df['Fork'].apply(lambda x: float(x.rstrip('k'))*1000 if x.endswith('k') else float(x))
github_df['Watch'] = github_df['Watch'].apply(lambda x: float(x.rstrip('k'))*1000 if 'k' in x else float(x))
# Remove , from issue and commits
github_df['Issues'] = github_df['Issues'].apply(lambda x: x.replace(',',''))
github_df['Commits'] = github_df['Commits'].apply(lambda x: x.replace(',',''))
# Convert multiple object columns to numeric
cols = ['Issues','Pull_Requests','Commits','Contributors']
github_df[cols] = github_df[cols].apply(pd.to_numeric, errors='coerce', axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment