更改熊猫数据框列中一种数据的类型

时间:2021-05-09 22:15:15

标签: python pandas string dataframe types

我正在尝试进行文本预处理,但我发现 text 列中的一个数据包含 float

i=0
while True:
    for each in list_df['text']:
        print(type(list_df['text'][i]))
        i+=1

enter image description here

如何将其更改为 str?

1 个答案:

答案 0 :(得分:1)

假设 col_x 是您的列名,请尝试:

df['col_x'] = df['col_x'].astype(str)