mardi 13 juillet 2021

python how to add IF statement in a map function using lambda

I have this following df:

d = {'role': ['admin/tech', 'admin', 'programming/asst/design']}
df = pd.DataFrame(data=d)

enter image description here

My goal is:

enter image description here

In other words, extract everything before the first '/' IF row contains '/'

I came up with:

enter image description here

and now I need to add a IF statement for this function

I tried something like:

enter image description here

But it doesn´t work.

Thanks in advance, I really appreciate suggestions!!

Aucun commentaire:

Enregistrer un commentaire