Top "Pandas-groupby" questions

To be used for grouping variables together based on a given condition.

How to move pandas data from index to column after multiple groupby

I have the following pandas dataframe: dfalph.head() token year uses books 386 xanthos 1830 3 3 387 xanthos 1840 1 1 388 xanthos 1840 2 2 389 xanthos 1868 2 2 390 xanthos 1875 1 1 I aggregate the …

python pandas pandas-groupby multi-index
How can I Group By Month from a Date field using Python/Pandas

I have a Data-frame df which is as follows: | date | Revenue | |-----------|---------| | 6/2/2017 | 100 | | 5/23/2017 | 200 | | 5/20/2017 | 300 | | 6/22/2017 | 400 | | 6/21/2017 | 500 | I need to group the above data …

python pandas pandas-groupby
Pandas, groupby and count

I have a dataframe say like this >>> df = pd.DataFrame({'user_id':['a','a','s','s','s'], …

python pandas pandas-groupby
Boxplot with pandas groupby multiindex, for specified sublevels from multiindex

Ok so I have a dataframe which contains timeseries data that has a multiline index for each columns. Here is …

python pandas dataframe pandas-groupby multi-index
How to do a conditional count after groupby on a Pandas Dataframe?

I have the following dataframe: key1 key2 0 a one 1 a two 2 b one 3 b two 4 a one 5 c two Now, …

python pandas dataframe pandas-groupby
Is there an "ungroup by" operation opposite to .groupby in pandas?

Suppose we take a pandas dataframe... name age family 0 john 1 1 1 jason 36 1 2 jane 32 1 3 jack 26 2 4 james 30 2 Then do a groupby() ... group_df = …

python pandas group-by pandas-groupby
Pandas: plot multiple time series DataFrame into a single plot

I have the following pandas DataFrame: time Group blocks 0 1 A 4 1 2 A 7 2 3 A 12 3 4 A 17 4 5 A 21 5 6 A 26 6 7 A 33 7 8 A 39 8 9 A 48 9 10 A 59 .... .... .... 36 35 A 231 37 1 …

python pandas matplotlib pandas-groupby
Python Pandas Conditional Sum with Groupby

Using sample data: df = pd.DataFrame({'key1' : ['a','a','b','b','a'], 'key2' : ['one', 'two', 'one', 'two', 'one'], …

python pandas pandas-groupby
How to do group by on a multiindex in pandas?

Below is my dataframe. I made some transformations to create the category column and dropped the original column it was …

python pandas dataframe pandas-groupby multi-index
group by pandas dataframe and select latest in each group

How to group values of pandas dataframe and select the latest(by date) from each group? For example, given a …

python pandas group-by pandas-groupby