Quantcast
Channel: Get all max and min values from df.groupby.().size() result - Stack Overflow
Browsing index pages (3 articles)
↧

Get all max and min values from df.groupby.().size() result

I have dataframe like thisdf = pd.DataFrame({'col1' : ['MM1', 'MM1', 'MM1', 'MM2', 'MM2', 'MM2', 'MM4', 'MM4', 'MM4'],'col2' : ['S1', 'S1', 'S3', 'S3', 'S4', 'S4', 'S2', 'S2', 'S2'],'col3' :...

View Article


Answer by jezrael for Get all max and min values from df.groupby.().size()...

Yiu can convert second level (col3) to column. so possible aggregate by GroupBy.agg with DataFrameGroupBy.idxmax and GroupBy.max:df1 = (df.groupby(["col1", "col3"]) .size() .reset_index(level=0)...

View Article


Answer by Ammar Bin Aamir for Get all max and min values from...

You can simply do this:df.groupby(["col1"])["col3"].max()

View Article
Browsing index pages (3 articles)


Latest Images