Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for dataset in train_df:
    pd.to_numeric(dataset['Embarked'].map( {'S': 0, 'C': 1, 'Q': 2}))


What I have tried:

I tried out to check using conditionality but it is not working too.
This is the error I am getting.

TypeError                                 Traceback (most recent call last)
<ipython-input-41-9e474db5d734> in <module>
      1 for dataset in train_df:
----> 2     pd.to_numeric(dataset['Embarked'].map( {'S': 0, 'C': 1, 'Q': 2}))

TypeError: string indices must be integers
Posted
Comments
Richard MacCutchan 17-Aug-19 9:18am    
What is the type of the variables train_df and dataset in the code above?
Member 14557966 18-Aug-19 0:19am    
See,train_df is a data frame and Embarked is a column in it with strings S, C,Q which I want to replace with numbers.But I am getting this error.So what to do now?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900