Reputation: 113
I have a data frame
df= pd.DataFrame({'PatientID': [1,2,3,4,5,6,7,8],'99' : ['1','0','1','0','1','0','1','0'],'75' : ['0','0','1','0','0','1','1','0'],'C604' : ['1','0','1','0','1','0','1','0'],'C602' : ['0','0','1','0','1','0','1','0'],'C601' : ['1','0','0','0','1','0','1','0'],'C603' : ['0','0','1','1','1','0','1','0'],'C605' : ['0','1','1','0','0','0','1','0'],'C606' : ['0','1','1','1','1','0','1','0'],'44' : ['1','0','1','0','1','0','1','0'],'L239' : ['0','0','1','1','1','0','1','0'], '32' : ['1','0','1','0','1','0','1','0'],}).set_index('PatientID')
When I try to add columns by doing
df.eval('(`99`+`75`)')I am getting this error
RecursionError: maximum recursion depth exceeded while calling a Python object
Trying to understand what this means and how I can solve this
Upvotes: 1
Views: 3353
Reputation: 169
Maybe easiest to change the datatype to int and then sum the columns '99' and '75' with the eval. If you really want to use that eval() function.
df = df.astype('int32')
df['new_column'] = df.eval('(`99`+`75`)')
Without eval() it is simply:
df['new'] = df['99'] + df['75']
Upvotes: 2