将Dataframe中的列转换为字符串会导致数据不完整,请增加字符串的长度

2024-10-03 09:12:20 发布

您现在位置:Python中文网/ 问答频道 /正文

数据帧的“A”列中的数据

'45-54 on Treatment for less than 1 month (Patient) '
'Ocetech| 65-74 Male  on Treatment for 10 years or more (Patient) '
'What is this?  Don't know screen name | 65-74 Female  on Treatment for 6 months to less than 1 year (Patient) '

将列“A”转换为字符串

c2 = c1.to_string(columns = ['A'])

将其转换并存储到c2后,行中的文本不完整,一半的文本不显示。你知道吗

电流输出:

'45-54 on Treatment for less than 1 ...
'Ocetech| 65-74 Male  on Treatment f...
'What is this?  Don't know scree...

我试图通过使用

c2 = c1['A'].astype('|S80')

但它显示出错误

SystemError: <class 'UnicodeEncodeError'> returned a result with an error set

Tags: 数据forisonthiswhatmaleless