Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to divide each column of pandas Dataframe by a Series?

I have a pandas dataframe in which I want to divide each column by the same data series values for each row. Each column and the data series have the same length. The data series has only float numbers but some cells in the dataframe have NaNs.

I tried various things but somehow I cannot get it solved.

df = df.divide(data_series, axis=1)

Any suggestions?

many thanks!

like image 849
Rolf12 Avatar asked May 31 '18 14:05

Rolf12


1 Answers

I found the solution

Setting axis = 0 solves the issue.

df = df.divide(data_series, axis=0 )

many thanks

like image 170
Rolf12 Avatar answered Oct 15 '22 21:10

Rolf12