Frank M
Frank M

Reputation: 25

pandas.errors.IndexingError: Too many indexers

getting the error message too many indexers using pandas. code below

import pandas as pd
userlist = ['Smith', 'Clark']
df = pd.read_csv("sample.csv")  

for i, df in df.iterrows():    
    if (df['Last Name']) in userlist:
        df.at[1,'Runner']='Yes'        
    else:
        pass


csv:
Last Name,Frist Name,email,Runner,Vistor
Doe,John,[email protected],Yes,Yes
Smith,Shawn,[email protected],No,Yes
Brown,Beth,[email protected],Yes,No
Clark,Tom,[email protected],No,Yes

I have a large data set with a list of names that need cell updates and will loop through the list to change the cells. Please help. Thanks

Upvotes: 0

Views: 305

Answers (1)

Ricardo
Ricardo

Reputation: 691

import pandas as pd
userlist = ['Smith', 'Clark']
df = pd.read_csv("sample.csv") 
df['Runner'][df['Last Name'].isin(userlist)]='Yes'

Upvotes: 1

Related Questions