简体   繁体   English

为什么我的列没有从 int 转换为字符串?

[英]Why isn't my column converting to string from int?

*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) 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.数据类型没有变化,它保持不变。

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'>
df = df.applymap(str)

This should work, it applies the map string throughout.这应该有效,它始终应用map string

If you want to see more methods go here .如果您想在此处查看更多方法 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM