如何从熊猫python中的数据集中删除unicode

时间:2018-11-16 04:14:03

标签: python string unicode

我有一个数据集名称rssfeeds,它是``''。如何删除此unicodes并替换为其原始值

我的数据集:- enter image description here

请帮助我

1 个答案:

答案 0 :(得分:1)

You can use Series.str.decode() on the columns with the offending encoding,,但如果您可以重新读取数据并直接访问它,我不喜欢这种方法。

读取数据时可以使用encoding='utf-8'参数,Pandas会尝试为您解决问题。假设您的数据在csv中且采用UTF-8编码,则类似这样:

df = pd.read_csv("yourfile.csv", encoding="utf-8")

编辑:您注意到您的数据是从数据库导入的,并且pandas.read_sql没有encoding arg。因此,我建议使用我的第一个建议Series.str.decode()。您将在列上这样使用它:

df["column_name"] = df["column_name"].str.decode("encoding_name")

如果遇到错误,可以传递errors,默认值是strict,但也可以ignore

df["column_name"] = df["column_name"].str.decode("encoding_name", errors="policy")