Jupyter Anaconda:将文本文件加载到 python 中

bot*_*bot 2 python anaconda jupyter jupyter-notebook

我在 Mac 上运行 Anaconda Python 和 Jupyter。键入以下代码后:

import numpy as np
import matplotlib.pyplot as plt
iris = np.genfromtxt("data/iris.txt",delimiter=None) 
Run Code Online (Sandbox Code Playgroud)

我收到错误:IOError: data/iris.txt not found. 我尝试将 iris 文件放在 anaconda 文件夹中:Users/anaconda/lib/python2.7

Muh*_*rif 8

在带有 Jupyter NoteBook 的 Anaconda Python 中,您必须像下面给出的那样用 \\ 给出绝对路径

import pandas as pd
df = pd.read_csv("D:\\Nu\\2SEMESTER\\Data Science\\Assignments\\Assignment-1 data\\file.txt")
df     # with this command you can see your file
Run Code Online (Sandbox Code Playgroud)