I have this dataframe:
df = pd.DataFrame({'FS':[1,1,2],'FL':[2,3,4],'GS':[5,8,9],'GL':[5,2,4],'JJ':['no','more','math']})
print(df)
FS FL GS GL JJ
0 1 2 5 5 no
1 1 3 8 2 more
2 2 4 9 4 math
I want to add columns between the 'L'(long) and 'S' (short) in a loop b/c this dataframe is 64 columns long, but stop before the column JJ, which is filled with strings. The operation that I want to perform for these columns is: Ratio = S/(S+L) so my dataframe would look like this:
df = pd.DataFrame({'FS':[1,1,2],'FL':[2,3,4],'FRatio':[0.333,0.25,0.333],\
'GS':[5,8,9],'GL':[5,2,4],'GRatio':[0.5,0.8,0.692],\
'JJ':['no','more','math']})
print(df)
FS FL FRatio GS GL GRatio JJ
0 1 2 0.333 5 5 0.500 no
1 1 3 0.250 8 2 0.800 more
2 2 4 0.333 9 4 0.692 math
I thought about melting the dataframe to a long format but each S/L pair is unique and I couldn't think of a way to keep them separated.