如何在Jupyter Notebook中加载CSV文件? [英] How to load CSV file in Jupyter Notebook?

查看:2975
本文介绍了如何在Jupyter Notebook中加载CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,正在学习机器学习.我偶然发现了我在网上找到的教程,我想使该程序正常工作,以便我更好地理解.但是,我在将CSV文件加载到Jupyter Notebook中时遇到问题.

I'm new and studying machine learning. I stumble upon a tutorial I found online and I'd like to make the program work so I'll get a better understanding. However, I'm getting problems about loading the CSV File into the Jupyter Notebook.

我收到此错误:

File "<ipython-input-2-70e07fb5b537>", line 2
    student_data = pd.read_csv("C:\Users\xxxx\Desktop\student-intervention- 
system\student-data.csv")
                          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in 
position 2-3: truncated \UXXXXXXXX escape

,这里是代码:

我在网上遵循了有关此错误的教程,但是没有一个有效.有谁知道如何修理它?

I followed tutorials online regarding this error but none worked. Does anyone know how to fix it?

第三次尝试使用路径"

3rd attempt with r"path"

我也尝试过"\"和utf-8,但是都没有用.

I've tried also "\" and utf-8 but none worked.

我正在使用最新版本的Anaconda Windows 7的 Python 3.7

I'm using the latest version of Anaconda Windows 7 Python 3.7

推荐答案

对Windows路径使用原始字符串表示法.在python中,"\"在python中具有含义.尝试改成像这样的字符串"r"路径:

Use raw string notation for your Windows path. In python '\' have meaning in python. Try instead do string like this r"path":

student_data = pd.read_csv(r"C:\Users\xxxx\Desktop\student-intervention- system\student-data.csv")

student_data = pd.read_csv(r"C:\Users\xxxx\Desktop\student-intervention- system\student-data.csv")

如果它不起作用,请尝试以下方式:

If it doesnt work try this way:

import os

path = os.path.join('c:' + os.sep, 'Users', 'xxxx', 'Desktop', 'student-intervention-system', 'student-data.csv')
student_data = pd.read_csv(path)

这篇关于如何在Jupyter Notebook中加载CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆