python


Syntax error in lambda with if expression


basic_salary['dem_education_level_numeric']=basic_salary['dem_education_level'].apply(lambda x : 3 if (x == 'high'))
I am getting below error:
SyntaxError: invalid syntax (<ipython-input-20-80adac538241>, line 1)
File "<ipython-input-20-80adac538241>", line 1
basic_salary['dem_education_level_numeric']=basic_salary['dem_education_level'].apply(lambda x : 3 if (x == 'high'))
^
SyntaxError: invalid syntax
Please help
Lambda statements need to return something, and without an else clause the return may be ambiguous. Change to:
basic_salary['dem_education_level_numeric']=basic_salary['dem_education_level'].apply(lambda x : 3 if x == 'high' else 0)
If you're going to have a if inside a lambda statement, an else must also be defined. Every lambda statement must return something, even if it's None. Change your lambda statement to this, by returning None if x isn't "high":
lambda x : 3 if x == 'high' else None # paralysis isn't necessary

Related Links

python csv fieldnames error
OpenCV : Vehicle axle detection
How to convert HTML to text keeping underline tags (<u></u>) using html2text
How to override settings.py with settings_local.py in Django 1.11
Format the color of a cell in a panda dataframe according to multiple conditions
Bokeh server callback initiated from Flask application
Python Variable Amount Of Input
Turn pandas dataframe list into boolean column
How to handle concatenate with empty matrix
python django translation .po and .mo file not translating the files
jupyter not using version set by pyenv
Generalize print+format for a variable number of inputs
What are the differences in these two codes? [closed]
What is the correct way to change image channel ordering between channels first and channels last?
Python to capture screenshot of big file
How can I compare the difference between digits of two numbers?

Categories

HOME
reverse-engineering
flyway
ll
histogrammar
devstack
bro
pygame
google-classroom
criteria
cakephp-2.9
hashicorp-vault
informatica-powercenter
activesync
simple-injector
dendrogram
saiku
primes
vs2017
avplayeritem
jflex
opencart2.3
onesignal
hash-collision
unpack
multichoiceitems
dhtmlx-scheduler
cell-array
roundcube
apache-cloudstack
exponential
preg-grep
geopy
pycparser
superpowered
honeysql
google-guava-cache
hashcat
rhel.net
alchemy.js
cross-entropy
bayesian-networks
amd
3scale
w3-total-cache
livescribe
info
heroku-postgres
search-box
project-template
verbose
cjson
uistackview
ruby-2.0
pagekit
squirrel
project-online
eml
anythingslider
loose-typing
intellitest
graphical-logo
start-job
lexicographic
tcpreplay
hidden-field
collabnet
argument-passing
java.util.date
cdata
astyanax
argb
adomd.net
xslkey
qt4.6
android-contextmenu
usn
icefaces-3
cosm
entity-framework-ctp5
nintendo
selectonemenu
scraperwiki
pivotal-crm
j-interop
idictionary
graph-layout
document-library

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile