【问题标题】:Why can't Pandas read my CSV?为什么 Pandas 无法读取我的 CSV?
【发布时间】:2016-04-02 18:04:50
【问题描述】:
import pandas as pd

path = r'‪C:\Users\matt\Documents\sample.csv'
sample = pd.read_csv(path)

print sample

IOError:文件 ‪C:\Users\matt\Documents\sample.csv 不存在

我试过了:

r'‪C:/Users/matt/Documents/sample.csv'
'‪C:/Users/matt/Documents/sample.csv'
'C:\\Users\\matt\\Documents\\sample.csv'

所有的结果都是一样的。

【问题讨论】:

  • os.path.exists(path) 返回 false!
  • print(path) 说什么?
  • 路径 = r'C:\Users\matt\Documents\sample.csv';打印路径;说 C:\Users\matt\Documents\sample.csv
  • 确保您使用的是正确的单引号 - 不要复制和粘贴它们 键入它们,与 C 相同 - 确保它是拉丁字符 C
  • 我猜这是单引号的美化(unicode)版本...

标签: python-2.7 csv pandas


【解决方案1】:

我的 C 之前的垃圾是问题。

……

这个垃圾来自我在路径中所做的复制粘贴。

手动输入文件路径即可解决问题。

【讨论】:

    猜你喜欢
    • 2019-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 2014-02-13
    • 1970-01-01
    • 2021-04-01
    • 2017-06-10
    • 2014-12-31
    相关资源
    最近更新 更多