Last active
August 26, 2020 19:41
-
-
Save msure/3bbaf49bba7dd016dce77f785ad43a18 to your computer and use it in GitHub Desktop.
Pandas Scratchpad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# faster/vectorized replacement for getting monthly cohort | |
df['months_elapsed'] = (df['stats_date'].dt.month - df['first_date'].dt.month) + (12 * (df['stats_date'].dt.year - df['first_date'].dt.year)) | |
# for handy functions (pandas, seaborn, etc.) where you need to reshape the dataframe first | |
df.query('some_filter == "2020-01-01" & another_filter != "error"').pipe(lambda x: pd.crosstab(x['variation'],x['customers'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment