Skip to content

Instantly share code, notes, and snippets.

@martinapugliese
Last active March 22, 2018 11:20
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 martinapugliese/a3113d1fc1b0a107871d541b84e015fe to your computer and use it in GitHub Desktop.
Save martinapugliese/a3113d1fc1b0a107871d541b84e015fe to your computer and use it in GitHub Desktop.

Pandas reference things

df is a DataFrame.

Grouping df on multiple functions and dropping hierarchical level

grouped_df = df.groupby(['colA', 'colB']) \
    .agg(
        {
            'ratio': {'avg_ratios': 'mean', 'std_ratios': 'std'},
            'n_swipes': {'sum_swipes': 'sum'}
        }).reset_index()

grouped_df.columns = grouped_df.columns.droplevel(0)

Customise pandas error bar

Pandas outer join with dates columns

Seems like it drops the not joined rows which are in one database and not in the other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment