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 in Python by Shri
2,376 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'])
answered Mar 28 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 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 by Alok

Related Questions In Python

0 votes
1 answer

Python error "TypeError: string indices must be integers, not str"

Hey @Dipti email_s.append(email_1["email_address"]) This is the list on ...READ MORE

answered Jul 5 in Python by Jinu
707 views
0 votes
1 answer
0 votes
1 answer

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

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,540 points
108 views
0 votes
1 answer

Python `if x is not None` or `if not x is None`?

There's no performance difference, as they compile ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,540 points
194 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 235 views
+4 votes
6 answers
0 votes
2 answers
0 votes
1 answer

Python TypeError: 'list' object is not callable.

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

answered Feb 8 in Python by Omkar
• 67,480 points
1,514 views