【问题标题】:I am trying to read a csv file using pandas but it fails to recognize it - what could be the issue? (Tkinter)我正在尝试使用 pandas 读取 csv 文件,但无法识别它 - 可能是什么问题? (Tkinter)
【发布时间】:2020-08-12 00:06:01
【问题描述】:

我一直在尝试使用 pandas 读取此 csv 文件,然后使用以下方法将其传输到字典:

pandas.read_csv("/Users/vijayaswani/Downloads/England1\ postcodes.csv ", index_col=1).T.to_dict()

但每次我收到错误No such file or directory

即使文件没有被删除或其他任何东西,使用文件名也不会使用文件名,也不会使用其路径。

可能是什么问题?

【问题讨论】:

  • 文件实际上不存在,或者您拼错了路径的某些部分。
  • 从不在文件或目录名称中使用任何空格
  • @rioV8:虽然这当然是实用的建议,但文件名中的空格在 Windows 和 OSX 上很常见。

标签: python python-3.x pandas csv tkinter


【解决方案1】:

您的文件路径中似乎有多余的空间。

你试过了吗:

pandas.read_csv("/Users/vijayaswani/Downloads/England1\ postcodes.csv", index_col=1).T.to_dict()

或者

pandas.read_csv("/Users/vijayaswani/Downloads/England1 postcodes.csv", index_col=1).T.to_dict()

【讨论】:

  • 我已经尝试了第一个但没有工作,并且没有考虑从路径中删除任何内容,因为它是我从终端完全复制的内容。第二个虽然有效。谢谢!!
猜你喜欢
  • 2020-09-24
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 2023-03-24
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多