python - How to perform aggregate options on one groupby column, giving two column outputs -


i performing bunch of aggregate stats on groupby data frame. 1 column in particular, ios_id, count , distinct count. i'm not sure how o output 2 seaparate columns different names. of right now, distinct count overwrites count.

how output both distinct count , count ios_id column 2 separate columns?

df_new = df.groupby('video_id').agg({"ios_id": np.count_nonzero,                                      "ios_id": pd.series.nunique,                                      "feed_position": np.average,                                      "time_watched": np.sum,                                      "video_length": np.sum}).sort('ios_id', ascending=false) 

something should work. note nested dictionary structure ios_id.

df_new = df.groupby('video_id').agg({"ios_id": {"count": "count",                                                 "distinct": "unique"},                                      "feed_position": np.average,                                      "time_watched": np.sum,                                      "video_length": np.sum}) 

for more details, please refer naming returned columns in pandas aggregate function:


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -