简体   繁体   中英

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:

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
  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')

在此处输入图像描述

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