Top "Pandas-groupby" questions

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

pandas: drop duplicates in groupby 'date'

In the dataframe below, I would like to eliminate the duplicate cid values so the output from df.groupby('date').…

python pandas duplicates unique pandas-groupby
What is the pandas equivalent of dplyr summarize/aggregate by multiple functions?

I'm having issues transitioning to pandas from R where dplyr package can easily group-by and perform multiple summarizations. Please help …

python r pandas pandas-groupby summarize
How to keep original index of a DataFrame after groupby 2 columns?

Is there any way I can retain the original index of my large dataframe after I perform a groupby? The …

python pandas dataframe indexing pandas-groupby
Add column for percentage of total to Pandas dataframe

I have a dataframe that I am doing a groupby() on to get the counts on a column's values. I …

python pandas group-by pandas-groupby
pandas: get all groupby values in an array

I'm sure this has been asked before, sorry if duplicate. Suppose I have the following dataframe: df = pd.DataFrame({'key': […

pandas pandas-groupby split-apply-combine
Get unique values of multiple columns as a new dataframe in pandas

Having pandas data frame df with at least columns C1,C2,C3 how would you get all the unique C1,…

python pandas pandas-groupby
Python Pandas: Calculate moving average within group

I have a dataframe containing time series for 100 objects: object period value 1 1 24 1 2 67 ... 1 1000 56 2 1 59 2 2 46 ... 2 1000 64 3 1 54 ... 100 1 451 100 2 153 ... 100 1000 21 I want to calculate moving average with window 10 …

python pandas pandas-groupby moving-average
Use pandas.shift() within a group

I have a dataframe with panel data, let's say it's time series for 100 different objects: object period value 1 1 24 1 2 67 ... 1 1000 56 2 1 59 2 2 46 ... 2 1000 64 3 1 54 ... 100 1 451 100 2 153 ... 100 1000 21 I want …

python pandas pandas-groupby
Groupby in python pandas: Fast Way

I want to improve the time of a groupby in python pandas. I have this code: df["Nbcontrats"] = df.groupby([…

python pandas numpy pandas-groupby
TypeError: unhashable type: 'list' when use groupby in python

There is something wrong when I use groupby method: data = pd.Series(np.random.randn(100),index=pd.date_range('01/01/2001…

python python-2.7 pandas pandas-groupby