Home > database >  Why isn't my column converting to string from int?
Why isn't my column converting to string from int?

Time:08-07

*Input:*
df["waiting_time"].value_counts()
​
*Output:*
2 days      6724
4 days      5290
1 days      5213
7 days      4906
6 days      4037
            ... 
132 days       1
125 days       1
117 days       1
146 days       1
123 days       1
Name: waiting_time, Length: 128, dtype: int64

I tried:

df['wait_dur'] = df['waiting_time'].values.astype(str)

and I've tried apply as well. No changes to the data type, it stays the same.

CodePudding user response:

You need to skip the 'values' part in your code:

    df['wait_dur'] = df['waiting_time'].astype(str)

If you check first row for example, you will get:

    type(df['wait_dur'][0])
    <class 'str'>

CodePudding user response:

df = df.applymap(str)

This should work, it applies the map string throughout.

If you want to see more methods go here.

  • Related