`
import pandas as pd
pd.set_option("display.width",1000)
url ="https://raw.githubusercontent.com/jokecamp/FootballData/master/UEFA_European_Championship/Euro%202012/Euro%202012%20stats%20TEAM.csv"
euro12 = pd.read_csv(url, sep=',')
只显示Goals这一列
print(euro12["Goals"])
print(euro12.Goals)
有多少至球队参与了2012欧洲杯
print(euro12.shape[0])
该数据集一共有多少列
print(euro12.info())
将数据集中的列Team,Yellow Cards和Red Cards单独存为一个名叫discipline的数据框
discipline = euro12[["Team","Yellow Cards","Red Cards"]]
print(discipline)
对数据框discipline按照先Red Cards再Yellow Cards排序
print(discipline.sort_values(["Red Cards","Yellow Cards"],ascending=False))
计算每个球队拿到黄牌的平均值
print(discipline['Yellow Cards'].mean())
对平均值取整
print(round(discipline['Yellow Cards'].mean()))
找到进球数Goals超过6的球队数据
print(euro12[euro12.Goals>6])
选取以字母G开头的球队数据
print(euro12[euro12.Team.str.startswith("G")])
选取前7列
print(euro12.iloc[:,0:7])
选取除了最后3列之外的全部列
print(euro12.iloc[:,:-3])
找到英格兰(England)、意大利(Italy)和俄罗斯(Russia)的射正率(shooting Accuracy)
print(euro12.loc[euro12.Team.isin(["England","Italy","Russia"]),['Team',"Shooting Accuracy"]])
本文由 所长 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Apr 23, 2018 at 08:08 am |