cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Python code error in dataflow

Edula
Explorer
0 Likes
1,001

Hi,

I'm very new to python, I hvae a data set with 13 column , once of the called 'gender'. I want to filter the data and result moved to Target table.

However I'm getting below error message called "'method' object is not subscriptable"

Edula_0-1748779691290.png

Please my code below, unfortunatly we can't debug the code in datasphere

def transform(data):
specific_name = ['Male']
df = data['gender'].isin[('specific_name')]
#data[NV]
return df

Any input would be greatly appreciated

Kind regards

Hari 

Accepted Solutions (1)

Accepted Solutions (1)

XaviPolo
Active Contributor
0 Likes

I believe there's a typo in your code, the isin function should be followed by parentheses () instead of brackets []
Like: df = data[data['gender'].isin(specific_name)]

Regards,

 

Edula
Explorer
0 Likes

Hi XaviPolo

Thanks for reply.

I have modified the code as you mentioend,however I'm still getting a syntax error as below.

def transform(data)
specific_name = ['Male']
df = data[data['gender'].isin(specific_name)]
return df

Edula_0-1748857287478.png

Kind regards

Hari

XaviPolo
Active Contributor
0 Likes

probably there is a typo related with tabs

def transform(data):
    specific_name = ['Male']
    df = data[data['gender'].isin(specific_name)]
    return df
Edula
Explorer
0 Likes
Hi XaviPolo, The same code works in python notebooks or google colabs , but not in Datashpere . I hope that those "isin" functions not available yet in Datasphere.I can't write "import pandas " in datasphere.
XaviPolo
Active Contributor
0 Likes

the previous code works for me.
check that you don't have prints or calls to dataframes to show the data in the console.

pandas is already imported by SAP

Regards,

Edula
Explorer
0 Likes

Hi, Below code worked for me

def transform(data):

specific_name = ['Male']

nv = data['gender'].isin(specific_name)

df= data[nv]

return df

Kind regards

Hari

Answers (0)