【问题标题】:Python: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Aditya Bhatt\\Desktop\\Aditya\\SampleData.csv'Python:FileNotFoundError:[Errno 2] 没有这样的文件或目录:'C:\\Users\\Aditya Bhatt\\Desktop\\Aditya\\SampleData.csv'
【发布时间】:2021-07-18 19:47:59
【问题描述】:

所以,这是我的代码...

filename = r"C:\Users\Aditya Bhatt\Desktop\Aditya\SampleData.csv" 
df = pd.read_csv(filename)

现在,它显示了这个错误:

FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'C:\Users\Aditya Bhatt\Desktop\Aditya\SampleData.csv'

文件位置为:“C:\Users\Aditya Bhatt\Desktop\Aditya”[已确认]
文件名:SampleData(.csv 文件)

我正在 Google Colab 上运行代码
另外,我从互联网上得到了这个文件(如果有帮助的话)

【问题讨论】:

  • 您无法直接从“Google Colab”访问本地文件。您将需要通过替代路线。如果你在 Colab 上,在左侧你会看到一个“文件”菜单,你可以通过它上传文件。然后你可以运行一些命令,比如import os print(os.listdir()) 来了解你在目录中得到了什么。希望这会有所帮助,否则请随时进一步询问。

标签: python google-colaboratory


【解决方案1】:

你必须放双反斜杠\\而不是单\

所以应该是这样的:

C:\something\assd\dada\x.csv

【讨论】:

    【解决方案2】:

    给你。 How to deal with local files in Google Colab

    由于 Colab 笔记本托管在 Google 的云服务器上,因此默认情况下无法直接访问本地驱动器(与托管在您的计算机上的笔记本不同)或任何其他环境中的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      相关资源
      最近更新 更多