0

I want to replace / add a new column to my dataframe which should contain city codes for the respective city name

Here's my dataframe

City
0   Alabama 
1   Alaska  
2   Arizona
3   Arkansas    
4   California

And I have another dataframe which has the city names with code

name    code
Alabama    US-AL
Alaska     US-AK
Arizona    US-AZ
Arkansas   US-AR
California US-CA

and here's my code

def iso(x):
    print(x)
    if x in list(country['name']):
        print(country[country['name']==x]['code'])
        return country[country['name']==x]['code'] 
    else:
        return ''

sales['city_code'] = sales['city'].apply(iso)

After running it I get this error

ValueError: Wrong number of items passed 50, placement implies 1
Vijayaraghavan
  • 255
  • 1
  • 2
  • 14

0 Answers0