df3 = {'chinese':109, 'American':88, 'German': 66, 'Korea':23, 'Japan':5, 'England':118}
df4 = pd.DataFrame(df3)
df4.plot(kind='barh', rot=0)
运行结果:ValueError: If using all scalar values, you must pass an index
原因:缺少索引
修改后:
#方式1:
df4 = pd.DataFrame.from_dict(df3,orient='index').T
df4.plot(kind='barh', rot=0)
print df4
#结果:
Korea England chinese German American Japan
0 23 118 109 66 88 5
#方式2:
df5 = pd.DataFrame({"key": df3.keys(), "value": df3.values()})
print df5
#结果为:
key value
0 Korea 23
1 England 118
2 chinese 109
3 German 66
4 American 88
5 Japan 5
# 作图语句:
df4.plot()
df5.plot(kind='barh', rot=0)
#运行以上语句图片不显示
#增加以下句子后出现图片
import matplotlib.pyplot as plt
plt.show()