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
Post a Comment