Reputation: 793
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.
Upvotes: 1
Views: 1682
Reputation: 793
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')
Upvotes: 2