簡體   English   中英

類型錯誤:不支持 / 的操作數類型:'str' 和 'int' (2)

[英]TypeError: unsupported operand type(s) for /: 'str' and 'int' (2)

我正在嘗試顯示包含數字和字母的數據集中的圖表。

grouped = pd.DataFrame(train.groupby(['shop_id', 'date_block_num'])['item_cnt_day'].sum().reset_index())
fig, axes = plt.subplots(nrows=5, ncols=2, sharex=True, sharey=True, figsize=(16,20))
num_graph = 10
id_per_graph = ceil(grouped.shop_id.max() / num_graph)
count = 0
for i in range(5):
    for j in range(2):
        sns.pointplot(x='date_block_num', y='item_cnt_day', hue='shop_id', data=grouped[np.logical_and(count*id_per_graph <= grouped['shop_id'], grouped['shop_id'] < (count+1)*id_per_graph)], ax=axes[i][j])
        count += 1

然后,它說:

TypeError                                 Traceback (most recent call last)
<ipython-input-19-77428a365041> in <module>
      2 fig, axes = plt.subplots(nrows=5, ncols=2, sharex=True, sharey=True, figsize=(16,20))
      3 num_graph = 10
----> 4 id_per_graph = ceil(grouped.shop_id.max() / num_graph)
      5 count = 0
      6 for i in range(5):

TypeError: unsupported operand type(s) for /: 'str' and 'int'

嘗試id_per_graph = ceil(max(grouped.shop_id) / num_graph)你使用的是.max()錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2025 STACKOOM.COM