Dataframe Divide Series On Pandas
I need to divide each column of the matrix df1 into a single column of the matrix df2. To get a matrix with dimension df1 (3*2). I need a result: dataframe[[1/6, 2/7, 3/8], [3/6, 4
Solution 1:
Here's one way:
pd.DataFrame(df1.values/ df2.values.T, columns=df1.columns)
iiiiii00.1666670.2857140.37510.5000000.5714290.625
Solution 2:
You can divide by Series
converted to array by Series.values
or Series.to_numpy
for pandas 0.24+:
df = df1.div(df2['i'].values)
#pandas 0.24+#df = df1.div(df2['i'].to_numpy())print (df)
i ii iii
a 0.166667 0.285714 0.375
b 0.500000 0.571429 0.625
Post a Comment for "Dataframe Divide Series On Pandas"