我已经在数据集中做了很多数据清理工作,以便能够在数据框中获得所有需要的信息。目前,我想对其进行可视化处理,但是得到的结果却毫无用处。
#combine dataframe
test = soccer_data_2.append(soccer_data_3)
test = test.sort_values(by = 'date')
test = pd.DataFrame(test, columns = ['date', 'Country', 'Result'])
#converte date format to only have year
test['date'] = pd.to_datetime(test['date'])
test['year'] = test['date'].dt.year
#group my result
test.set_index('year', inplace=True)
test = test.groupby(['year', 'Country', 'Result']).Result.count()
print(test)
year Country Result
1873 England Win 1
Scotland Win 1
1874 England Win 1
Scotland Win 1
1876 England Win 1
..
2019 Yorkshire Win 2
Zambia Win 5
Zimbabwe Win 7
2020 Costa Rica Win 1
United States Win 1
我想找到一种绘制时间序列的方法,并查看每个国家胜利的演变情况。
尝试这个:
plt.figure(figsize=(10,10))
countries=df.Country.unique()
for country in countries:
grouped=df[df.Country==country].groupby('year').count()
years=list(grouped.index)
wins=list(grouped.Result)
plt.plot(years,wins,label=country)
plt.legend()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句