Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 条形图为-:';返回不支持的操作数类型;str';和';浮动';_Python_Pandas_Matplotlib_Bar Chart - Fatal编程技术网

Python 条形图为-:';返回不支持的操作数类型;str';和';浮动';

Python 条形图为-:';返回不支持的操作数类型;str';和';浮动';,python,pandas,matplotlib,bar-chart,Python,Pandas,Matplotlib,Bar Chart,我尝试使用以下代码绘制pivot_表的条形图: fig=plt.figure(figsize=(10,10)) ax1=fig.add_subplot(111) ax1.bar(Products.index,Products["Amount"].values) 透视表如下所示: Amount Material 454T006S R 167 134:11

我尝试使用以下代码绘制pivot_表的条形图:

fig=plt.figure(figsize=(10,10))
ax1=fig.add_subplot(111)

ax1.bar(Products.index,Products["Amount"].values)
透视表如下所示:

                                      Amount
Material                             
454T006S R 167 134:11                0.000000
3457T006S R IE216 167 246:1          4.500000
67T009S R 1510K304:1              36.000000
7676009S R IE216 1510K304:1        30.500000
676T012S 167 246:1                  1.000000
2324T012S R 1510 111                6.000000
1516T012S R 1510 151               50.500000
1516T012S R 1510 20:1               26.500000
但它的回报是:

-:“str”和“float”的操作数类型不受支持


我做错了什么?

问题是您的索引值是
字符串

我认为最简单的是使用:

您可以将字符串的值映射到
范围
、打印范围和最后添加
xticks

fig=plt.figure(figsize=(10,10))
ax1=fig.add_subplot(111)

idx=Products.index.tolist()
x = range(len(idx))

plt.bar(x, Products["Amount"].values)
plt.xticks(x, idx, rotation=90)
plt.show()
类似的解决方案是
重置索引
,默认情况下打印
索引

fig=plt.figure(figsize=(10,10))
ax1=fig.add_subplot(111)

Products = Products.reset_index()
plt.bar(Products.index, Products["Amount"].values)
plt.xticks(Products.index, Products['Material'], rotation=90)
plt.show()

问题是索引值是
字符串

我认为最简单的是使用:

您可以将字符串的值映射到
范围
、打印范围和最后添加
xticks

fig=plt.figure(figsize=(10,10))
ax1=fig.add_subplot(111)

idx=Products.index.tolist()
x = range(len(idx))

plt.bar(x, Products["Amount"].values)
plt.xticks(x, idx, rotation=90)
plt.show()
类似的解决方案是
重置索引
,默认情况下打印
索引

fig=plt.figure(figsize=(10,10))
ax1=fig.add_subplot(111)

Products = Products.reset_index()
plt.bar(Products.index, Products["Amount"].values)
plt.xticks(Products.index, Products['Material'], rotation=90)
plt.show()