Issue
I am curious about the fastest solution for my case, what is the way to transform all the values in years 1-4 into a percentage of the Freq column with the lowest amount of code possible.
df = pd.DataFrame({'Delivery Year' : [1976,1977,1978,1979], "Freq" : [120,100,80,60],
"1. Year" : [10,3,8,14],
"2. Year" : [5,float('nan'),5,float('nan')],
"3. Year" : [10,10,float('nan'),float('nan')],
"4. Year" : [13,float('nan'),float('nan'),float('nan')]
})
df
Thank you
Solution
This would be my take on it:
for i in ['1. Year', '2. Year', '3. Year', '4. Year']:
df[i] = df[i]/df['Freq']
Answered By - ql.user2511
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.