![Insert picture description here](https://img-blog.csdnimg.cn/20210310183826735.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
import pandas as pd
import numpy as np
d = {
'Name':['Alisa','Bobby','Cathrine','Alisa','Bobby','Cathrine',
'Alisa','Bobby','Cathrine','Alisa','Bobby','Cathrine'],
'Semester':['Semester 1','Semester 1','Semester 1','Semester 1','Semester 1','Semester 1',
'Semester 2','Semester 2','Semester 2','Semester 2','Semester 2','Semester 2'],
'Subject':['Mathematics','Mathematics','Mathematics','Science','Science','Science',
'Mathematics','Mathematics','Mathematics','Science','Science','Science'],
'Score':[62,47,55,74,31,77,85,63,42,67,89,81]}
df = pd.DataFrame(d)
df
![Insert picture description here](https://img-blog.csdnimg.cn/20210310184750884.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
df.pivot_table(values='Score', index='Semester', columns='Subject', aggfunc=np.sum)
![Insert picture description here](https://img-blog.csdnimg.cn/2021031018483989.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
df.pivot_table(values='Score', index='Semester', columns='Subject', margins=True, aggfunc=np.sum)
![Insert picture description here](https://img-blog.csdnimg.cn/20210310184925360.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
df.pivot_table(values='Score', index='Semester', columns='Subject', aggfunc={
'mean', 'max', 'min'})
![Insert picture description here](https://img-blog.csdnimg.cn/20210310185003236.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
cars_df = pd.read_csv('../data/cars.csv')
cars_df.head()
![Insert picture description here](https://img-blog.csdnimg.cn/2021031018502881.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)
cars_df.pivot_table(values='(kW)', index='YEAR', columns='Make')
![Insert picture description here](https://img-blog.csdnimg.cn/20210310185048674.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpbGRu,size_16,color_FFFFFF,t_70)