1

I have a dataframe df as:

                        Col1          Col2
Date                                      
2014-06-06              43.69         4.67
2014-06-09              45.47         4.70
2014-06-10              43.19         4.72
2014-06-11              47.58         4.64

I have another datafrmae df2 as:

              Col1       Col2                 
0              2         .5

I want to divide df with df2 to get the following:

enter image description here

But I am not sure how to perform this in a pythonic way?

Zanam
  • 4,607
  • 13
  • 67
  • 143

2 Answers2

2

IIUC using numpy will remove the index match

df1[:]=df1.values/df2.values
df1
              Col1  Col2
Date                    
2014-06-06  21.845  9.34
2014-06-09  22.735  9.40
2014-06-10  21.595  9.44
2014-06-11  23.790  9.28
BENY
  • 317,841
  • 20
  • 164
  • 234
1

Math between a dataframe and a series aligns the series index with the dataframe columns by default. Soooo, get the first row of df2 and you're set

df1 / df2.iloc[0]

              Col1  Col2
Date                    
2014-06-06  21.845  9.34
2014-06-09  22.735  9.40
2014-06-10  21.595  9.44
2014-06-11  23.790  9.28

If you want to alter the dataframe

df1 /= df2.iloc[0]

df1

Date                    
2014-06-06  21.845  9.34
2014-06-09  22.735  9.40
2014-06-10  21.595  9.44
2014-06-11  23.790  9.28

SEE THIS POST
For more information.

piRSquared
  • 285,575
  • 57
  • 475
  • 624