'Strange error when setting values in a pandas DataFrame
This loop is working to change other columns in my DataFrame. But I keep running into this error on this specific column/dataframe. I'm basically trying do in a VLOOKUP between tables in Pandas.
KeyError: 'cannot use a single bool to index into setitem'
This code is working fine with no errors. It returns the appropiate value to the "Adjusted Agency" column
for i in range(len(df_ult_cust)):
df.loc[df.Ult_Cust == df_ult_cust['Ult_Cust'].iloc[i], 'Adjusted Agency'] = df_ult_cust['ACRONYM'].iloc[i]
But when I use this block of code, I get that strange key error listed above.
for j in range(len(df_pca_cust)):
df.loc[df.div == df_pca_cust['pca'].iloc[j], 'Division'] = df_pca_cust['div_acronym'].iloc[j]
Note: I chose not to use the itterows Pandas function here as for some reason it was causing the code to run slower.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
