1

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

ScottC
  • 3,941
  • 1
  • 6
  • 20
  • This may help: https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers – ScottC Nov 26 '22 at 03:29
  • Can you show us how you are populating the `bank` variable? Is it a dataframe? Is it a list ? – ScottC Dec 10 '22 at 00:00

1 Answers1

1

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

enter image description here

Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42