Python 更改panda dataframe列中一个数据的类型
我正在尝试进行文本预处理,但我发现我的Python 更改panda dataframe列中一个数据的类型,python,pandas,string,dataframe,types,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 如何将其更改为str?假设col\u x是您的列名,请尝试: df['col_x'] = df['col_x'].astype(str) df['text'].astype(str)将整个列转换为字符串。您可以使用
text
列中有一个数据包含float
i=0
while True:
for each in list_df['text']:
print(type(list_df['text'][i]))
i+=1
如何将其更改为str?假设
col\u x
是您的列名,请尝试:
df['col_x'] = df['col_x'].astype(str)
df['text'].astype(str)
将整个列转换为字符串。您可以使用apply
df['text'].astype(str).apply(type)
@Umar.H进行检查谢谢您的回答