如何将Pandas Data Frame(csv文件)中的特殊字符/符号替换为NaN

问题描述 投票:0回答:1

大家好,

 I am new to the handling of data in pandas DataFrame could you please help me to solve the problem.

 My question is how to replace special symbols(like ?,@,#,$,&,^ and so on) with NaN.

例如:我的CSV文件(((Ram.csv)文件看起来像这样

enter image description here

enter image description here

python-3.x pandas csv replace special-characters
1个回答
0
投票
替换特殊符号(例如?,@,#,$,&,^等)

如果该列仅支持字母,则可以检查字母的ASCII并替换其ASCII与字母的ASCII不匹配的其他任何字符。您可以使用上述登录名将特殊字符替换为空字符串,然后使用用NaN替换它们。

df.replace(r'^\s*$', np.nan, regex=True)
© www.soinside.com 2019 - 2024. All rights reserved.