1 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個贊
df1-df4
想法是使用by創(chuàng)建一個 Dataframe concat
,僅在列表理解中將Finish
列轉(zhuǎn)換為數(shù)字,并且還通過索引。Series.str.extract
Season
DataFrame.set_index
最后的情節(jié)DataFrame.plot
:
names = ['Pistons','Lions','Red Wings','Tigers']
df_list = [df1, df2, df3, df4]
new = [x.set_index('Season')['Finish'].str.extract('(\d+)', expand=False).astype(int)
for x in df_list]
df = pd.concat(new, axis=1, keys=names)
print (df)
Pistons Lions Red Wings Tigers
Season
1950 4 4 1 2
1951 3 2 1 5
1952 4 1 1 8
1953 3 1 1 6
1954 3 1 1 5
df.plot()
plt.gca().invert_yaxis()
plt.title("Season vs Finish Position Graph", fontsize=17)
plt.xlabel('Season (Year)', fontsize=13)
plt.ylabel('Finish Position', fontsize=13)
plt.legend(loc=4, fontsize=10, frameon=False)
plt.show()
添加回答
舉報