Samir
Samir

Reputation: 25

TypeError: 'tuple' object is not callable np.where

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

Answers (1)

jezrael
jezrael

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

Related Questions