I have a dataframe with 2 columns
- 'job_title' (filled with all the possible job titles)
- 'profile_type' (empty)
Conditions:
s1 = pd.Series(df['job_title'])
#checking if the job title contains any of the following conditions
condition1 = s1.str.contains('Head|VP|COO|CEO|CMO|CLO|Chief|Partner|Founder|Owner|CIO|CTO|President|Leaders', flags=re.IGNORECASE, regex=True)
condition2 = s1.str.contains('Senior|Consultant|Manager|Learning|Training|Talent|HR|Human Resources|Consultant|L&D|Lead', flags=re.IGNORECASE, regex=True)
Query:
if condition1.any() == True:
df_new['profile_type'] == 'Decision Maker'
elif condition2.any() == True:
df_new['profile_type'] == 'Key Influencer'
else:
df_new['profile_type'] == 'Influencer'
Could someone tell me what is incorrect in this code as it does not return anything. In the output, the profile type is still empty.
I have also tried the below code
data_dm = pd.Series(['Head', 'VP', 'COO' 'CEO', 'CMO','CLO', 'Chief', 'Partner', 'Founder', 'Owner', 'CIO', 'CTO', 'President', 'Leaders'])
data_ki = pd.Series(['Senior', 'Consultant', 'Manager', 'Learning', 'Training', 'Talent', 'HR', 'Human Resources', 'Consultant', 'L&D', 'Lead'])
def condition(x):
if x==data_dm.all():
return "Decision Maker"
elif x==data_ki.all():
return "Key Influencer"
else:
return 'Influencer'
df_new['profile_type'] = df_new['job_title'].apply(condition)
This returns only the value in the 'else' condition. The column profile_type only has the value 'Influencer'
I want the column named 'profile_type' to be filled with 'Decision maker', 'Key Influencer' or 'Influencer' based on the job titles.
Expected Output:
Output:
job_title profile_type
0 -
1 English trainer Influencer
2 Learning and Development Specialist Key Influencer
3 Director of Training Key Influencer
4 Director of Training Key Influencer
5 CEO Decision Maker
6 facilitator Influencer
7 Talent Development Partner Influencer
8 L&D Key Influencer
9 L&D Key Influencer
Is there any other method that I can use or try?
Any help is appreciated. Thanks in advance.