Last active
July 15, 2019 16:40
-
-
Save dumbledad/0cf900c0cff3366807436cbbb81c64b1 to your computer and use it in GitHub Desktop.
Why does nunique overwrite the grouping column in pandas
This file contains hidden or 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
import pandas as pd | |
import numpy as np | |
df = pd.DataFrame({'user_id':[1,1,1,2,2,2],'module_id':[1,2,3,1,1,2]}) | |
print(df) | |
print(df.groupby('user_id', as_index=False).sum()) | |
print(df.groupby('user_id', as_index=False).nunique()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment