2017-10-18 12 views
0

を私は次のコードでpivot_tableのバープロットをプロットしてみ:Barplotがサポートされていないオペランドタイプ(複数可)を返す - :「STR」と「フロート」

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' と 'フロート'

私は間違っていますか?

答えて

1

問題のインデックス値はstringsです。

私は最も単純で pandas.DataFrame.plot.barを使用すると思い

Products["Amount"].plot.bar() 

あなたは、rangeに文字列の値をマッピングプロット範囲と最後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() 

同様のソリューションは、デフォルトでreset indexとプロットであるindex

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() 
関連する問題