0

I'm a following a pandas tutorial and came across with the function "apply". I already have one column ("speaker name") with random values and I'd like to update its rows based on the values on another row. My code is:

df["speaker name"].apply(lambda row: "cian" if df["speaker id"]==5)

Python output:

 df["speaker name"].apply(lambda row: "cian" if df["speaker id"]==5)
                                                                   ^
 SyntaxError: invalid syntax

could you help me with this?

Thanks

little_mice
  • 177
  • 6
  • Is tutorial online? How looks tutorial valid solution? – jezrael Feb 17 '21 at 07:11
  • It's a tutorial, but they only show the case when you create a column from another one. This case, is just one example that came to my mind while following the tutorial. What they to in the video is: df["speaker name"]=df["speaker id"].apply(lambda x: "Robert" if x==4), but in my case I want to substituted an already existing one – little_mice Feb 18 '21 at 04:04
  • I think tutorial is wrong `df["speaker name"]=df["speaker id"].apply(lambda x: "Robert" if x==4)` it not valid pandas code. So for you it raise error too. – jezrael Feb 18 '21 at 05:31
  • 1
    Thank you @jezrael. If that's the case then I'm going to close this question – little_mice Feb 18 '21 at 10:33

0 Answers0