0

I have 2 dataframes like this

df1=
   col1 col2 col3 col4 col5
    A    B    C   2    3
    A    C    V   3    4

df2=

   col1 col2 col3 col4 col5
    A    B    C   4    4
    A    C    V   3    4

I am merging these two tables on col1,col2, col3 and want to evaluate df1[col4]-df2[col4] and df1[col5]-df2[col5]

I am merging the dataframes like this.

newDF=df1.merge(df2, on=[col1, col2, col3], suffixes=['_df1', '-df2'])

newDF.eval('col4_Diff=col4_df1-col4_df2', 'col5_Diff=col5_df1-cold_df2', inplace=True')

I am getting this error on the eval operation.

TypeError: eval() got multiple values for argument 'inplace'

How do i get rid of the error? is eval() single argument only?

Bounty Collector
  • 615
  • 7
  • 19

1 Answers1

2

you put it all in the same string. you also had a single quote character after True.

newDF.eval("""
col4_Diff=col4_df1-col4_df2
col5_Diff=col5_df1-cold_df2
""", inplace=True)
matthewmturner
  • 566
  • 7
  • 21