Is There In Pandas Operation Complementary (opposite) To Groupby?
I have a table (data frame) with many columns. Now I would like to average values in one of the columns. It means that I need to group by over all columns except the one over which
Solution 1:
You are searching for the complementary columns to a list you have on hands. You can play with df.columns
. It represents an Index
object that allows some interesting manipulations.
df.columns.drop(['col6'])
returns an Index
with the list of columns passed as argument removed. You can convert it into a list and use it as the groupby
argument:
df.groupby(df.columns.drop(['col6']).tolist())['vals'].mean()
Post a Comment for "Is There In Pandas Operation Complementary (opposite) To Groupby?"