“Grupa autorstwa Pandas” Kod odpowiedzi

grupa według liczby danych danych

df.groupby(['col1', 'col2']).size().reset_index(name='counts')
Crazy Caterpillar

Pandas New DF z Groupby

df = pd.DataFrame(old_df.groupby(['groupby_attribute'])['mean_attribute'].mean())
df = df.reset_index()
df
Cheerful Cheetah

Grupa Pandy przez

data.groupby('amount', as_index=False).agg({"duration": "sum"})
Tirbo06

Groupby as_index = false

When you use as_index=False , you indicate to groupby() that you don't want to set the column ID as the index (duh!). ... Using as_index=True allows you to apply a sum over axis=1 without specifying the names of the columns, then summing the value over axis 0.
Dhwaj Sharma

Grupują ramkę danych za pomocą określonych kolumn

# Groups the DataFrame using the specified columns

df.groupBy().avg().collect()
# [Row(avg(age)=3.5)]
sorted(df.groupBy('name').agg({'age': 'mean'}).collect())
# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
sorted(df.groupBy(df.name).avg().collect())
# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
sorted(df.groupBy(['name', df.age]).count().collect())
# [Row(name='Alice', age=2, count=1), Row(name='Bob', age=5, count=1)]
Ethercourt.ml

Grupa autorstwa Pandas

#calculate sum of sales grouped by month
df.groupby(df.date.dt.month)['sales'].sum()

date
1    34
2    44
3    31
Name: sales, dtype: int64
Vannia Hnatiuk

Odpowiedzi podobne do “Grupa autorstwa Pandas”

Pytania podobne do “Grupa autorstwa Pandas”

Więcej pokrewnych odpowiedzi na “Grupa autorstwa Pandas” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu