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