Python pandas TypeError tuple indices must be integers or slices not str

0 votes

Hi. Please help me solve this error. I am trying to print row values

import pandas as pd

df = pd.read_csv(“/home/user/data1”)

for row in df.iterrows():
    print (row['Email'])
Mar 28, 2019 in Python by Shri
48,280 views

3 answers to this question.

0 votes

df.iterrows() returns a tuple with index and the row value. So, you will have handle both the index and the value. Try this:

import pandas as pd

df = pd.read_csv(“/home/user/data1”)

for index, row in df.iterrows():
    print (row['Email'])

Hope this helps!!

If you need to learn more about Python, It's recommended to join Python Training today.

Thanks!

answered Mar 28, 2019 by Jackie
0 votes
iterrows() method returns a tuple of form: (index, row)

so you'd have to use row[1]['Email'] to get what you're looking for
answered Jun 13, 2019 by rahuldev

I get the following error when I try row[1]['Email']

TypeError: string indices must be integers, not str
0 votes
In fact, I get a perfectly good output with this logic. Can you share your dataset's data structure?
answered Jun 13, 2019 by Alok

Related Questions In Python

0 votes
0 answers

TypeError: tuple indices must be integers or slices, not tuple

Traceback (most recent call last):   File "main.py", line ...READ MORE

Aug 25, 2020 in Python by Peddabudi srikanth
• 120 points
4,372 views
0 votes
1 answer

TypeError: list indices must be integers or slices, not str

Hi@akhtar, As we know that the index of ...READ MORE

answered Oct 15, 2020 in Python by MD
• 95,440 points
13,398 views
0 votes
0 answers

TypeError: tuple indices must be integers or slices, not tuple

Im a begginer and im trying to ...READ MORE

Oct 19, 2020 in Python by peyman
• 120 points

edited Oct 19, 2020 by Gitika 861 views
+1 vote
1 answer

Can anyone help me with this error: TypeError: list indices must be integers or slices, not str

Hi, @Varshap  It’s a TypeError, which tells us ...READ MORE

answered Nov 5, 2020 in Python by anonymous
• 65,910 points
2,028 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,411 views
0 votes
3 answers

'python' is not recognized as an internal or external command

Try "py" instead of "python" from command line: C:\Users\Cpsa>py Python 3.4.1 (v3.4.1:c0e311e010fc, May ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
2,064 views
0 votes
1 answer

Python TypeError: 'list' object is not callable.

The error says the list is not ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,210 points
28,746 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP