1

Trying to convert kaggle titanic dataset pclass column datatype from int to string. Using pandas 1.0.5.

df.Pclass.head()
0    3
1    1
2    3
3    1
4    3
Name: Pclass, dtype: int64

Code is below:

df['Pclass'] = df['Pclass'].astype('string')

Thrown error as below:

ValueError: StringArray requires a sequence of strings or pandas.NA

Note: This worked for first time,not sure from 2nd time onwards keep getting this error.

1 Answer 1

2

The below code worked. As pandas >= 1.0, they have suggested to use string instead of str. But if source is numeric then we can use str instead of string to work.

df['Pclass'] = df['Pclass'].astype('str')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.