pandas_groupby
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
pandas_groupby [2024/03/26 22:25] – [groupby slicing] raju | pandas_groupby [2024/05/07 20:46] – [extract groupby object by key] raju | ||
---|---|---|---|
Line 235: | Line 235: | ||
Ref: https:// | Ref: https:// | ||
+ | |||
+ | ==== filter elements from groups that dont satisfy a criterion ==== | ||
+ | tags | pandas groupby filter groups | ||
+ | < | ||
+ | In [2]: | ||
+ | import pandas as pd | ||
+ | df = pd.DataFrame({ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | df | ||
+ | Out[2]: | ||
+ | | ||
+ | 0 foo 1 2.0 | ||
+ | 1 bar 2 5.0 | ||
+ | 2 foo 3 8.0 | ||
+ | 3 bar 4 1.0 | ||
+ | 4 foo 5 2.0 | ||
+ | 5 bar 6 9.0 | ||
+ | |||
+ | In [3]: | ||
+ | grouped = df.groupby(' | ||
+ | |||
+ | In [4]: | ||
+ | grouped.filter(lambda x: x[' | ||
+ | Out[4]: | ||
+ | | ||
+ | 1 bar 2 5.0 | ||
+ | 3 bar 4 1.0 | ||
+ | 5 bar 6 9.0 | ||
+ | </ | ||
==== extract groupby object by key ==== | ==== extract groupby object by key ==== |
pandas_groupby.txt · Last modified: 2024/05/07 20:47 by raju