0

I'm new to this page. I've managed to find myself in a little bit of an issue. Using python I'm looking for a way to loop through the different cells of an excel column using pandas and dataframes. The code I'm using is:

variable = pd.DataFrame(data, columns=['Column'])
for cell in variable:
    print(cell)

And this only prints the first cell. What am I doing wrong?

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
Lucas Peck
  • 15
  • 6
  • See this answer https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas what you've got is a pandas dataframe. By looping over it as you are, pandas lets you loop over the columns. If you want the rows, try the methods in the linked answer. – grbeazley Jun 07 '22 at 17:20

1 Answers1

0

Not exactly sure what you are trying to do but here is a way to remove duplicate entries of the same text within a column in a dataframe.

df = df[df.column_name.apply(lambda x: x != 'Player')]

This loops through the whole column in the dataframe and ofcourse you can update the code to the action you want after the colon.

  • What I am trying to do is by using a 'for loop' cycling through the different cells on a determined column. So I can after that apply it to an SOAP request so that I can automate every time a new request is introduced. For example: having in one column the client ID and the second the amount they are trying to charge it. Edit: Sorry if I'm not being clear, I'm from Argentina and my english it's a bit rusty. – Lucas Peck Jun 07 '22 at 21:01