Answers for "pandas dataframe sorted after groupby"

1

pandas sort values group by

df.groupby(['job']).apply(lambda x: (x.groupby('source')
                                      .sum()
                                      .sort_values('count', ascending=False))
                                     .head(3))
Posted by: Guest on June-04-2020
0

sort values within groups pandas dataframe

import pandas as pd

df = pd.DataFrame({'A':[1, 2, 3, 4, 5, 6],
                   'B':[0, 1, 2, 0, 1, 2]})

df.groupby('B').apply(lambda x: x.sort_values('A', ascending = True))
Posted by: Guest on August-18-2020

Code answers related to "pandas dataframe sorted after groupby"

Python Answers by Framework

Browse Popular Code Answers by Language