Skip to content

Instantly share code, notes, and snippets.

@ReidWilliams
Last active February 22, 2018 14:47
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 ReidWilliams/b9166c2e2950c6bd54845e82c8adebfa to your computer and use it in GitHub Desktop.
Save ReidWilliams/b9166c2e2950c6bd54845e82c8adebfa to your computer and use it in GitHub Desktop.
Pandas cheatsheet
# rename a dataframe column
dataframe = dataframe.rename(index=str, columns={'old_col_name': 'new_col_name'})
# get all possible values for a string / categorical column
dataframe[column].value_counts(dropna=False)
# group data and count number of rows in a group
grouped = dataframe.groupby(color)
nreds = len(grouped.get_group('red'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment