python Programming Glossary: df.groupby
GroupBy functions in Python Pandas like SUM(col_1*col_2), weighted average etc http://stackoverflow.com/questions/10009468/groupby-functions-in-python-pandas-like-sumcol-1col-2-weighted-average-etc on my machine faster to use df 'helper' df.a df.b grouped df.groupby something grouped 'helper' .sum df.drop 'helper' axis 1 But..
Pandas DataFrame aggregate function using multiple columns http://stackoverflow.com/questions/10951341/pandas-dataframe-aggregate-function-using-multiple-columns will be called on each sub DataFrame. For example grouped df.groupby keys def wavg group d group 'data' w group 'weights' return..
pandas: apply function to DataFrame that can return multiple rows http://stackoverflow.com/questions/13050003/pandas-apply-function-to-dataframe-that-can-return-multiple-rows 0 return DataFrame 'class' row 'class' row 'count' df.groupby 'class' group_keys False .apply f so you get In 25 df.groupby.. 'class' group_keys False .apply f so you get In 25 df.groupby 'class' group_keys False .apply f Out 25 class 0 A 0 C 1 C You..
How to access pandas groupby dataframe by key http://stackoverflow.com/questions/14734533/how-to-access-pandas-groupby-dataframe-by-key 'bar' 3 'B' rand.randn 6 'C' rand.randint 0 20 6 gb df.groupby 'A' I can iterate through it to get the keys and groups In 11..
Pandas sort by group aggregate and column http://stackoverflow.com/questions/14941366/pandas-sort-by-group-aggregate-and-column . So basically get the order of the A groups with In 28 df.groupby 'A' .sum .sort 'B' Out 28 B C A baz 2.829710 1 bar 0.253651.. pandas share improve this question Groupby A In 0 grp df.groupby 'A' Within each group sum over B and broadcast the values using..
Pandas group by operations on a data frame http://stackoverflow.com/questions/16684346/pandas-group-by-operations-on-a-data-frame pandas share improve this question Something like df.groupby 'UsrId' .JobNos.sum .idxmax should do it In 1 import pandas.. 1 In 4 df pd.read_csv StringIO data sep ' s ' In 5 grouped df.groupby 'UsrId' In 6 grouped.JobNos.sum Out 6 UsrId 1 85 2 124 3 79..
Session generation from log file analysis with pandas http://stackoverflow.com/questions/17547391/session-generation-from-log-file-analysis-with-pandas this time difference Hope the problem is clear. sessions df.groupby 'IP' 'Agent' .size UPDATE df.index is like follows class 'pandas.tseries.index.DatetimeIndex'.. ip 0 1.1 A 1 1.7 A 2 2.5 A 3 2.6 B 4 2.7 B 5 3.4 B In 24 g df.groupby 'ip' In 25 df 'session_number' g 'time' .apply lambda s s s.shift..
python pandas groupby() result http://stackoverflow.com/questions/17666075/python-pandas-groupby-result groupby and it kind of works res for a group_by_A in df.groupby 'A' group_by_B group_by_A.groupby 'B' as_index False res a group_by_B.. work in one go with an apply I can't get it . In 11 g df.groupby 'A' 'B' In 12 df1 df.set_index 'A' 'B' The size groupby function..
pandas: Filling missing values within a group http://stackoverflow.com/questions/18265930/pandas-filling-missing-values-within-a-group if there is a better way to achieve this. df 'cs_name' df.groupby 'trial' 'cs_name' .ffill df 'cs_name' df.groupby 'trial' 'cs_name'.. 'cs_name' df.groupby 'trial' 'cs_name' .ffill df 'cs_name' df.groupby 'trial' 'cs_name' .bfill Expected output cs_name trial 0 A1.. is to use first_valid_index and a transform In 11 g df.groupby 'trial' In 12 g 'cs_name' .transform lambda s s.loc s.first_valid_index..
|