Normalizing pandas DataFrame rows by their sums

To overcome the broadcasting issue, you can use the div method:

df.div(df.sum(axis=1), axis=0)

See pandas User Guide: Matching / broadcasting behavior

Leave a Comment