“Groupby Pandas” Kode Jawaban

panda DF baru dari groupby

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

grup panda oleh

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

Nilai Pandas Groupby dalam daftar

pd.DataFrame( {'a':['A','A','B','B','B','C'], 'b':[1,2,5,5,4,6]})
df.groupby('a')['b'].apply(list)

Out: 
a
A       [1, 2]
B    [5, 5, 4]
C          [6]
Name: b, dtype: object
Plif Plouf

Mengelompokkan DataFrame menggunakan kolom yang ditentukan

# 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

Groupby Pandas

>>> emp.groupby(['dept', 'gender']).agg({'salary':'mean'}).round(-3)
Uninterested Unicorn

Jawaban yang mirip dengan “Groupby Pandas”

Pertanyaan yang mirip dengan “Groupby Pandas”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya