1 import pandas 2 import numpy 3 csv=pandas.read_csv('salesmen.csv') 4 csv['Month']=pandas.DatetimeIndex(csv['Date']).month 5 6 #透视表制作方法一: 7 #pt=csv.pivot_table(index='Salesman',columns='Year',values='Revenue',aggfunc=numpy.sum) 8 9 #透视表制作方法二: 10 group=csv.groupby(['Salesman','Month']) 11 s=group['Revenue'].sum() 12 c=group['Revenue'].count() 13 pt1=pandas.DataFrame({'Sum':s,'Count':c}) 14 print(pt1)