且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Pandas 读取 UTF-8 文件?

更新时间:2023-11-27 12:09:58

正如其他海报提到的,你可以尝试:

As the other poster mentioned, you might try:

df = pd.read_csv('1459966468_324.csv', encoding='utf8')

但是,当您打印 dtypes 时,这仍然可能让您看到对象".要确认它们是 utf8,请在阅读 CSV 后尝试这一行:

However this could still leave you looking at 'object' when you print the dtypes. To confirm they are utf8, try this line after reading the CSV:

df.apply(lambda x: pd.lib.infer_dtype(x.values))

示例输出:

args            unicode
date         datetime64
host            unicode
kwargs          unicode
operation       unicode