1>>> table = pd.pivot_table(df, values=['D', 'E'], index=['A', 'C'],
2... aggfunc={'D': np.mean,
3... 'E': [min, max, np.mean]})
4>>> table
5 D E
6 mean max mean min
7A C
8bar large 5.500000 9.0 7.500000 6.0
9 small 5.500000 9.0 8.500000 8.0
10foo large 2.000000 5.0 4.500000 4.0
11 small 2.333333 6.0 4.333333 2.0
12
1>>> df = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two',
2... 'two'],
3... 'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
4... 'baz': [1, 2, 3, 4, 5, 6],
5... 'zoo': ['x', 'y', 'z', 'q', 'w', 't']})
6>>> df
7
8>>df.pivot(index='foo', columns='bar', values=['baz', 'zoo'])
9bar A B C
10foo
11one 1 2 3
12two 4 5 6
1>>> emp.pivot_table(index='dept', columns='gender', values='salary', aggfunc='mean').round(-3)
1# Tips is the Dataframe:
2# Suppose we want to compute a table of group means, we can
3# use the Pivot_Table Method:
4
5# The Pivot Table automatically computes the mean
6
7tips.pivot_table(index=['day', 'smoker'])
8
9# The index represents the column names that you want to form groups
1df.pivot_table(['int_age'],index = [df.iloc[:,meet_friends], df.iloc[:,friendsgiving]])