I have two DataFrames
, as follows :
df1 =
name1 name2 name3 .... nameXXX
5.1 1.2 1.1 ... 223.2
3.22 1.34 1.5 ... 213.2
4.3 1.32 1.23 ... 523.2
5.2 1.1 1.543 ... 223.2
df2=
name1 0.2
name2 0.1
name3 0.43
... ...
nameXXX 0.21
What I need :
df3=
name1 name2 name3 ... nameXXX
5.1 * 0.2 1.2 * 0.1 1.1 * 0.43 ... 223.2 * 0.21
3.22* 0.2 1.34* 0.1 1.5 * 0.43 ... 213.2 * 0.21
4.3 * 0.2 1.32* 0.1 1.2 * 0.43 ... 523.2 * 0.21
5.2 * 0.2 1.1 * 0.1 1.54* 0.43 ... 223.2 * 0.21
the
name
s are the column headersBasically I want to multiply each column of
df1
by the number present indf2
that is in the same row of the column header ofdf1
I saw the following questions but I couldn't find the solution to my problem :
1) How to select rows from a DataFrame based on column values?
2)Pandas: pairwise multiplication of columns based on column name
3) Multiply columns of a dataframe by getting the column names from a list
4)pandas: Select dataframe columns based on another dataframe's columns