Python Forum
if- elif- and condition issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if- elif- and condition issue
#1
Hi All,

Need your help on one issue.
I have a dataframe 'df' which has 3 columns of 'object' data type- opt1,opt2,opt3
Now I need to create a new column 'var' which will have followings-
1. if opt2 and opt 3 are None/Null/Empty and opt1 is not None/Null/Empty:
then df[var] = df[opt1]
2. elif opt1 and opt 3 are None/Null/Empty and opt2 is None/Null/Empty:
then df[var] = df[opt1] + '|' + df[opt3]
3. elif opt1 and opt 2 are None/Null/Empty and opt3 is None/Null/Empty:
then df[var] = df[opt1] + '|' + df[opt2]
4. else: df[var] = df[opt1] + '|' + df[opt2] + '|' + df[opt3]

Please suggest me to put above conditions in Python 3.6 or share me any better approach.

Thanks!
Reply


Messages In This Thread
if- elif- and condition issue - by PrateekG - May-15-2018, 05:33 AM
RE: if- elif- and condition issue - by scidam - May-16-2018, 02:06 AM
RE: if- elif- and condition issue - by wavic - May-16-2018, 03:30 AM
RE: if- elif- and condition issue - by scidam - May-16-2018, 03:45 AM
RE: if- elif- and condition issue - by PrateekG - May-16-2018, 06:44 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020