“Pandas Groupby Beberapa kolom” Kode Jawaban

DataFrame Groupby beberapa kolom

grouped_multiple = df.groupby(['Team', 'Pos']).agg({'Age': ['mean', 'min', 'max']})
grouped_multiple.columns = ['age_mean', 'age_min', 'age_max']
grouped_multiple = grouped_multiple.reset_index()
print(grouped_multiple)
Unsightly Unicorn

grup oleh, agregat beberapa kolom -panda

df[['col1', 'col2', 'col3', 'col4']].groupby(['col1', 'col2']).agg(['mean', 'count'])
Panicky Pony

Mengelompokkan beberapa kolom dalam panda

import pandas as pd

# Group multiple columns and get statistics
df = df.groupby(["store", "type"])["weekly_sales"].sum()

# Group multiple columns and multiple statistics
df = df.groupby(["store", "type"])["weekly_sales"].agg([sum, min, max])

# Display DataFrame
print(df)
Elisabeth Engering

grup dengan 2 kolom panda

In [11]: df.groupby(['col5', 'col2']).size()
Out[11]:
col5  col2
1     A       1
      D       3
2     B       2
3     A       3
      C       1
4     B       1
5     B       2
6     B       1
dtype: int64
Hungry Horse

Pandas Groupby Beberapa kolom

#formatting
candidates_salary_by_month =  candidates_df.groupby('month').agg(num_cand_month = \
                                                                ('num_candidates', 'sum'), \
                                                                avg_sal = ('salary', 'mean')).style.format('{:.0f}')

print(candidates_salary_by_month)
Colorful Caterpillar

Pandas Groupby Beberapa kolom

df['COUNTER'] =1       #initially, set that counter to 1.
group_data = df.groupby(['Alphabet','Words'])['COUNTER'].sum() #sum function
print(group_data)
Novid19

Jawaban yang mirip dengan “Pandas Groupby Beberapa kolom”

Pertanyaan yang mirip dengan “Pandas Groupby Beberapa kolom”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya