I have a large dataframe with effective numbers of several items and want to change them into relative frequency. So I added a column that sums all values in the columns for each row :
product apple pear banana sum
Jean 3 5 1 9
Phil 2 7 1 10
Yanis 5 4 4 14
Next I have to apply the formula x/sum(X)*100 to get the relative frequency for each value in the dataframe in order to get a dataframe like this :
product apple pear banana
Jean 33.33 55.55 11.11
Phil 20 70 10
Yanis 37.71 28.57 28.57
I don't really know how to do this without specifying each columns (this is just a small dataset for the example)
My code for now :
df = pd.read_csv(f, sep="\t", index_col='product')
dff = df.transpose()
dff["sum"] = dff.sum(axis=1)
Thank you in advance