Reputation: 25
I am trying to create a new pandas dataFrame column using the numpy.where() function. Can someone tell me why I get the error "TypeError: 'tuple' object is not callable"
The line of code generating the error: data1['y']=np.where(data1.KINETIC.str.contains("AF"),1,0)
When I execute data1.KINETIC.str.contains("AF") I get the expected result: 0 True 1 False 2 True 3 True 4 True 5 False ... data1 is a pandas dataframe.
Upvotes: 1
Views: 537
Reputation: 862431
I believe you need assign to same DataFrame
called data1
:
data1['data1']=np.where(data1.KINETIC.str.contains("AF"),1,0)
Or use alternative with casting True/False
to 1/0
:
data1['data1']=data1.KINETIC.str.contains("AF").astype(int)
Upvotes: 1