Update: Now I am getting the below error: AttributeError: 'list' object has no attribute 'str' , I think the original error was due to the fact that I needed 2 square brackets in the code for the Dataframe to be recognized as a Dataframe rather than a series. now I have this
AttributeError: 'list' object has no attribute 'str'
Updated Code
## Create list of Privileged accounts
Search_for_These_values = ['Privileged','Diagnostics','SYS','service account'] #creating list
pattern = '|'.join(Search_for_These_values) # joining list for comparision
PrivilegedAccounts_DF['PrivilegedAccess'] = PrivilegedAccounts_DF.columns=[['first_name']].str.contains(pattern)
PrivilegedAccounts_DF['PrivilegedAccess'] = PrivilegedAccounts_DF['PrivilegedAccess'].map({True: 'True', False: 'False'})
ORIGINAL Question:
I'm just wondering how one might overcome the below error.
TypeError: only integer scalar arrays can be converted to a scalar index
I am using the below code on a pandas dataframe (126 rows × 6 columns) What I am trying to do is create a new column "PrivilegedAccess" and in this column I want to write "True" if any of the names in the first_names column match the ones outlined in the "Search_for_These_values" list and "False" if they don't
SAMPLE DATA:
uid last_name first_name language role email_address department
0 121 Chad Diagnostics English Team Lead Michael.chad@gmail.com Data Scientist
1 253 Montegu Paulo Spanish CIO Paulo.Montegu@gmail.com Marketing
2 545 Mitchel Susan English Team Lead Susan.Mitchel@gmail.com Data Scientist
3 555 Vuvko Matia Polish Marketing Lead Matia.Vuvko@gmail.com Marketing
4 568 Sisk Ivan English Supply Chain Lead Ivan.Sisk@gmail.com Supply Chain
5 475 Andrea Patrice Spanish Sales Graduate Patrice.Andrea@gmail.com Sales
6 365 Akkinapalli Cherifa French Supply Chain Assistance Cherifa.Akkinapalli@gmail.com Supply Chain
CODE:
## Create list of Privileged accounts
Search_for_These_values = ['Privileged','Diagnostics','SYS','service account'] #creating list
pattern = '|'.join(Search_for_These_values) # joining list for comparision
PrivilegedAccounts_DF['PrivilegedAccess'] = PrivilegedAccounts_DF['first_name'].str.contains(pattern)
PrivilegedAccounts_DF['PrivilegedAccess'] = PrivilegedAccounts_DF['PrivilegedAccess'].map({True: 'Yes', False: 'No'})
Many thanks