如何使用Pandas或numpy绘制两列(String + double)

时间:2021-12-12 23:46:47

I have a dataFrame and I want to plot two columns. All the examples i saw used only numbers as their values but when I try to plot a columns that has strings then I get an error. How can I plot a string columns?

我有一个dataFrame,我想绘制两列。我看到的所有示例都只使用数字作为它们的值,但是当我尝试绘制具有字符串的列时,我得到一个错误。如何绘制字符串列?

d = {'one' : np.random.rand(10),
     'two' : np.random.rand(10)}
df = pd.DataFrame(d)
df.plot(style=['o','rx'])
plt.show()

DataFrame sample (I want to plot AvgTemp and StateName)

DataFrame示例(我想绘制AvgTemp和StateName)

STATION;"STATION_NAME";"LATITUDE";"LONGITUDE";"LATLONG";"AvgTemp";"MaxTemp";"MinTemp";"StateName";"Zip";"State";"Date"

GHCND:USW00094746;"WORCESTER MA US";42.2706;-71...   -71.8731";55.0;58.0;47.0;"Massachusetts";1602... 

1 个解决方案

#1


1  

IIUC, Here's a minimal example of what you want to do:

IIUC,这是您想要做的最小例子:

df = pd.DataFrame({'state': ['a','b','a','c','b','c'], 'value':[23,43,12,87,33,11]})
df.groupby('state')['value'].mean().plot(kind='bar')

如何使用Pandas或numpy绘制两列(String + double)

#1


1  

IIUC, Here's a minimal example of what you want to do:

IIUC,这是您想要做的最小例子:

df = pd.DataFrame({'state': ['a','b','a','c','b','c'], 'value':[23,43,12,87,33,11]})
df.groupby('state')['value'].mean().plot(kind='bar')

如何使用Pandas或numpy绘制两列(String + double)