0

I have a dataframe1(1273 rows x 40 columns), and i have another dataframe2 (1273 rows x columns 1).

I want to do subtraction between the 2 dataframes in order to have a new dataframe called AMP(1273 rows x 40 columns).

The subtraction must be like this ( for each row of dataframe1 - row of dataframe2)

I tried this function : dataframe1.sub(dataframe2, axis= 0 )

However, it does only subtraction on the first row and Nans on the others row.

Any suggestions about how this can be done?

Nuke
  • 1,032
  • 7
  • 13
  • Did you try `axis=1` for testing? – Paulo Marques Apr 12 '21 at 14:09
  • 2
    Wlecome to SO. Please read [mre]. Your questions should always include a minimal example of any data you are operating on/with - enough for us to be able to reproduce your problem. [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – wwii Apr 12 '21 at 14:15
  • `df.sub(dg.iloc[:,0],0)` - You need to *specify* the Series - the second DataFrame's column - for the subtraction. – wwii Apr 12 '21 at 14:29
  • Yes i tried axis=1 – Joseph Dougmi Apr 12 '21 at 15:08
  • @wwii thank you so much for youranswer it works very well. just a small favore can you expalin to me more your syntaxe. I know that iloc let you select the all rows and the column 0, bur what do you mean about the last 0 that you add. – Joseph Dougmi Apr 12 '21 at 15:16
  • `DataFrame.sub(Series,axis=0)` – wwii Apr 12 '21 at 15:23

0 Answers0