#首先导入需要的类库
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# 导入数据
data=pd.read_csv('F:文档kobi.csv')
print(data.shape)
print(data.describe())
# PTS是场均得分,G是上场比赛次数
total_points=(data.PTS*data.G).sum()
avg_points=total_points/data.G.sum()
print(u'常规赛总得分:',total_points)
print(u'常规赛均得分:',avg_points)
max_point=data.PTS.max()
print(data[data.PTS==max_point])
print(data.loc[data.PTS>=30])
max_data={'point':data.PTS.max(),
'rebounds':data.TRB.max(),
'assistants':data.AST.max(),
'steals':data.STL.max(),
'blocks':data.BLK.max()}
best_kobi=pd.Series(max_data)
print(best_kobi)
# 可视化数据
#
# x轴用20年(1997-2016)的年份
# y轴是每个赛季的得分情况
#
x=pd.date_range('1997','2016',freq='365D')
y=data.PTS
plt.xlabel('season')
plt.ylabel('points')
plt.plot(x,y)
plt.show()
x=np.array([x for x in range(1997,2017)])
y=data.AST
plt.xlabel('season')
plt.ylabel('points')
plt.bar(x,y,width=0.5,color='m')
plt.xticks(x)
ax=plt.gca()
x_lables=ax.xaxis
for each in x_lables.get_ticklabels():
each.set_rotation(-45)
plt.show()