df.pivot_table

38

table = pd.pivot_table(df, values='D', index=['A', 'B'],
...                     columns=['C'], aggfunc=np.sum)
>>> table
C        large  small
A   B
bar one    4.0    5.0
    two    7.0    6.0
foo one    4.0    1.0
    two    NaN    6.0
>>> emp.pivot_table(index='dept', columns='gender',                     values='salary', aggfunc='mean').round(-3)
# Simplest pivot table must have a dataframe
# and an index/list of index.
table = pd.pivot_table(df, index =['A', 'B'])
  
table
table = pd.pivot_table(df, values='D', index=['A', 'B'],
...                     columns=['C'], aggfunc=np.sum)
df.pivot(index='foo', columns='bar', values=['baz', 'zoo'])

Comments

Submit
0 Comments