0

I`ve a large dataframe, Im trying to do a simple multipication between two columns and put the results in new column when I do that I'm getting this error message :

SettingWithCopyWarning : a value is trying to be set on a copy of a slice from a dataframe.

my code looks like this :

DF[‘mult‘]=DF[‘price‘]*DF[‘rate‘]

I Tried loc but didnt work .. does anyone have a solution ?

habdie
  • 109
  • 7

1 Answers1

0

You should use df.assign() in this case:

df2 = DF.assign(mult=DF[‘price‘]*DF[‘rate‘])

You get back a new dataframe with a 'mult' column added.

Artem Trunov
  • 1,340
  • 9
  • 16