Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Python by (19.9k points)

I am trying to print each entry of the dataframe separately. The dataframe is created by reading a csv file. This is the code I am using:

import pandas as pd

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

for row in df.rows:

    print (row)

But I am getting this error:

AttributeError: 'DataFrame' object has no attribute 'rows'

1 Answer

0 votes
by (25.1k points)

This is because you need to reference the iterrows method to get access to the row iterator of a dataframe. Like this:import pandas as pd

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

for row in df.iterrows():

    print (row)

If you want to get a deeper understanding of data science and libraries used in it you can watch this youtube video: 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...