ValueError:无法将字符串转换为浮点数:无聊
这是我的数据框。ValueError:无法将字符串转换为浮点数:无聊
tag score
0 hiding 63.0
1 windowsill 1.0
2 porch 1.0
3 deck 1.0
4 bored 1.0
我在试图根据标签绘制分数。
tag_df = pd.DataFrame(list(tag_map.items()), columns=['tag', 'score'])
plt.plot(tag_df['tag'], tag_df['score'], color='blue')
我碰到下面的错误,
ValueError: could not convert string to float: 'bored'
我在做什么错在这里?
试试这个:
df.plot.bar(x='tag', y='score', rot=0)
这里是a great Pandas Visualisation tutorial with tons of examples
这实际上起作用。你能解释一下你的答案为什么这个工作以及为什么前一个没有。在这个语法中,也是plt,就像我如何在不使用plt变量的情况下访问matplotlib一样。这甚至使用matplotlit? –
@MelissaStewart请参阅['pandas.Dataframe.plot()']的文档(http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html#pandas.DataFrame.plot ) – excaza
@MelissaStewart,这是一个标准的方式在熊猫的阴谋。请阅读[教程](http://pandas.pydata.org/pandas-docs/stable/visualization.html) - 我不认为我可以更好地解释它 – MaxU
什么是'autotag_map'? – sgrg
这是我从中获取数据帧的散列表。 –
我更新了代码以包含matplotlib行。 –