Pandas读取excel与中文文件名 [英] Pandas read excel with Chinese filename

查看:2701
本文介绍了Pandas读取excel与中文文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试过:

  df = pd.read_excel(url / Somebody 2008.xls)

  import sys 
df = pd.read_excel / somebody 2008.xls,encoding = sys.getfilesystemencoding())

像:没有这样的文件或目录url / \xa1\xa92008.xls



我也尝试使用os.rename更改文件的名称,但文件名甚至不能正确读取(要求python只打印文件名只产生问号或正方形)。

解决方案

  df = pd.read_excel(uurl / Somebody 2008.xls,encoding = sys.getfilesystemencoding())

可能会工作...但您可能必须在文件顶部声明一个编码类型


I am trying to load as a pandas dataframe a file that has Chinese characters in its name.

I've tried:

df=pd.read_excel("url/某物2008.xls")

and

import sys
df=pd.read_excel("url/某物2008.xls", encoding=sys.getfilesystemencoding())

But the response is something like: "no such file or directory "url/\xa1\xa92008.xls"

I've also tried changing the names of the files using os.rename, but the filenames aren't even read properly (asking python to just print the filenames yields only question marks or squares).

解决方案

df=pd.read_excel(u"url/某物2008.xls", encoding=sys.getfilesystemencoding())

may work... but you may have to declare an encoding type at the top of the file

这篇关于Pandas读取excel与中文文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆