Skip to content Skip to sidebar Skip to footer

Pandas: Multiplying Dataframes

I am trying to multiplicate a whole dataframe size 40 row * 600 columns by a pandas.core.series.Series with 40 row and only one columns. So my goal is to multiply all the rows by t

Solution 1:

Use the mul method to execute an element-wise multiplication between two DataFrames:

k = df1.mul(df2)

If you're still having trouble due to the first DataFrame having the column in days, then you can convert it to an int or float before performing the element-wise multiplication step:

import numpy as np
df1.col1 = (df1.col1.values / np.timedelta64(1, 'D')).astype(int)

Post a Comment for "Pandas: Multiplying Dataframes"