简体   繁体   中英

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

I'm trying to show the graph from my dataset which contains numbers and letters.

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

Then, it says:

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()错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM