What does .div do in Pandas (Python)
You can divide one dataframe by another and pandas will automagically aligned the index and columns and subsequently divide the appropriate values. EG df1 / df2
If you divide a dataframe by series, pandas automatically aligns the series index with the columns of the dataframe. It maybe that you want to align the index of the series with the index of the dataframe instead. If this is the case, then you will have to use the div
method.
So instead of:
df / s
You use
df.div(s, axis=0)
Which says to align the index of s
with the index of df
then perform the division while broadcasting over the other dimension, in this case columns.