0

The issue I am having is that I want a ratio column after every variable, and not at the very end. say my dataframe is df =

 A    B   C  total
15   30  45  90
20   30  50  100
10   20  30  60

I want to include the ratios so it looks like this

 A    Aratio   B  Bratio  C Cratio  total
15      .166   30   .333  45   .50    90
20       .20   30    .30  50   .50   100
10      .166   20   .333  30   .50    60

instead of

A B C Total Aratio Bratio Cratio

is there a way to when I use a for loop, to have the ratio fall immediately after the variable?

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
nrd271
  • 1

1 Answers1

0

I believe you can create a column only at the end of the dataframe. What you can do though is reorder the columns after creating the ratios columns:

df = df[["A", "Aratio", "B", "Bratio", "C", "Cratio", "total"]]
Matteo Zanoni
  • 3,429
  • 9
  • 27