使用Jupyter笔记本中的pandas导入csv文件时出现FileNotFoundError

时间:2017-10-09 10:01:55

标签: python pandas csv import-csv

Screenshot of the described error.

import pandas as pd
df = pd.read_csv('/home/josepm/Documents/test_ver2.csv')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-5cd7fd573fb7> in <module>()
      1 import pandas as pd
----> 2 df = pd.read_csv('/home/josepm/Documents/test_ver2.csv')

我尝试使用pandas导入CSV文件,每次它都说它找不到文件。就像Jupyter没有看到它一样。我试着这样做:

import os
os.path.isfile('/home/josepm/Documents/test_ver2.csv')

并且它也没有看到该文件。

3 个答案:

答案 0 :(得分:2)

更改

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HybridMavenProject</groupId>
<artifactId>Learning_Selenium</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
 </plugins>
 </build>
 <dependencies>
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.6.0</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20.1</version>
</dependency>
</dependencies>
</project>

pd.read_csv('\Users\user\Desktop\Workbook1.csv')

答案 1 :(得分:0)

请尝试以下代码:

import os  
path = os.path.abspath(r'file path')
f = open(path)
print(f)

答案 2 :(得分:0)

  

工作目录是在Jupyter Notebook中访问所有文件的位置。

     

找到当前工作目录

     

导入操作系统

     

os.getcwd()

     

o / p示例:'C:\ Users \ xyz'

     

现在将CSV文件放在此路径

     

列出目录内容以检查CSV文件是否存在

     

os.listdir('C:\ Users \ xyz')

     

现在尝试读取CSV文件