0

I am trying to print rows of a dataframe one by one. I only manage to loop over the columns instead of the rows:

first I am importing from a csv:

table_csv = pd.read_csv(r'C:\Users\xxx\Desktop\table.csv',sep=';', error_bad_lines=False)

Next, I convert into a datframe using pandas:

table_dataframe = DataFrame(table_csv)

I then start the for loop as follows:

for row in table_dataframe:
print(row)

It however loops over the columns instead of the instead over the row. However i need to perform alterations on rows. Does anybody know where this goes wrong or has an alternative solution?

wow
  • 13
  • 3
  • Does this answer your question? [How to iterate over rows in a DataFrame in Pandas](https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas) – Alessandro Nov 01 '21 at 10:09

1 Answers1

0

Check out answers to this question

In short this is how you'd do it:

for index, row in table_dataframe.iterrows():
    print(row)
PumpkinPie
  • 111
  • 1
  • 6
  • that prints out the rows separated per column, so it starts with first column and then just prints all the rows contained and then moves to the second column etc..I need it to print out the rows one by one without this column separation – wow Nov 01 '21 at 11:22