Skip to content

Instantly share code, notes, and snippets.

@ayoskovich
Created August 17, 2020 19:12
Show Gist options
  • Save ayoskovich/611624523c3e81593c705a3e9229ef30 to your computer and use it in GitHub Desktop.
Save ayoskovich/611624523c3e81593c705a3e9229ef30 to your computer and use it in GitHub Desktop.
Create table containing counts AND proportions.
# 'counts' will be the name of the new column
# 'date' will be the index of the dataframe
x = df['date'].value_counts().to_frame('counts')
x['prop'] = x['counts'] / x['counts'].sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment