vendredi 20 mars 2020

Python Data Frame if and for syntax error

When I'm attempting to run the following command, I'm receiving a "invalid syntax" error which I have pasted below

Command:

Orig_df['Generation'] = [Val if x > LBY and x < UBY for x in ['birth_year']]

Error

    Orig_df['Generation'] = [Val if x > LBY and x < UBY for x in ['birth_year']]
                                                      ^

SyntaxError: invalid syntax

I am unable to work out what I am doing wrong.

For clarity the ^ is pointed at the r on the for - I wasn't able to work out how to correct on here

Thanks for help in advance

Aucun commentaire:

Enregistrer un commentaire