I have a df with more than 300 rows and more than 4000 columns. A sample of the Df looks like this:
| AB | BC | DA | DC | FF |
|---|---|---|---|---|
| 40 | 50 | 4 | 10 | 60 |
| 10 | 20 | 10 | 5 | 20 |
I want to create another DF by dividing all the observation by cells of column DC so that i will have a df that looks like this:
| AB | BC | DA | DC | FF |
|---|---|---|---|---|
| 4 | 5 | 0.4 | 1 | 6 |
| 1 | 2 | 1 | 0.2 | 2 |
an Idea that came to my mind was iterrows but I could not find my way around it.
any better suggestion on how to do this?
CodePudding user response:
This should get you what you want
for column in df.columns:
if column == 'DC':
pass # this just does nothing and skip the column
else:
df[col] = df[col] / df['DC']
