简体   繁体   English

有什么方法可以修复错误字符串索引必须是整数?

[英]Is there any way I can fix the error string indices must be integers?

I tried to make graphs for my csv dataset in Jupyter Notebook, using this line of code:我尝试使用以下代码行在 Jupyter Notebook 中为我的 csv 数据集制作图表:

bank['marital'].value_counts().plot(kind='pie',autopct='%.2f') 
plt.show()

However, the system return, "string indices must be integers".但是,系统返回“字符串索引必须是整数”。

I have tried to use many different methods like changing the string to a number,... but nothing really worked我尝试使用许多不同的方法,例如将字符串更改为数字,......但没有任何效果

I tried to reproduce it and it worked fine.我试图重现它并且它工作正常。 So it's not something wrong with the code itself.所以这不是代码本身的问题。 I suggest experimenting with:我建议尝试:

  1. restart Jupyter Notebook重启 Jupyter Notebook
  2. play with a tiny synthetic dataset玩一个小的合成数据集
  3. cut the real dataset till it works剪切真实数据集直到它工作
  4. attach failing dataset contents to the question将失败的数据集内容附加到问题

Attaching my results:附上我的结果:

[input.csv]
name,smth
Maria,12
Anton,2
Maria,3
...

df = pd.read_csv('input.csv')
df['name'].value_counts().plot(kind='pie',autopct='%.2f')

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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