I'm working on a base that has 35 columns and 3047 rows. One of the columns is 'State' which consists of 50 states in the USA, and I want to convert that states into numeric values ,e.g. Washington is 1, West Virginia 2, etc.
df.loc[df['State']=='Washington','State']=1
df.loc[df['State']=='West Virginia','State']=2
.
.
df.loc[df['State']=='Arizona','State']=50
df['State']=df['State'].astype(str).astype(int)
I got this error: ValueError: invalid literal for int() with base 10:'Washington'. Can anyone help me? What can I do to fix this problem? Do you know some other way to convert dtype object in int? Thanks in advance