What am I doing wrong with this syntax of multiple if – else in apply pandas?
Advertisements I am trying to execute this code: data[‘lga_code’] = data.loc[:,’lga’].apply(lambda x: ‘Rural’ if x == endswith(‘Rural’) (‘Urban’ if x == endswith(‘Urban’) else ‘other’)) But I get this error: SyntaxError: invalid syntax. What is wrong? The data is a dataframe that it has 125 categories. I want to group them all into three, and that’s… Read More What am I doing wrong with this syntax of multiple if – else in apply pandas?