'CSV不存在'-Pandas DataFrame [英] 'CSV does not exist' - Pandas DataFrame

查看:93
本文介绍了'CSV不存在'-Pandas DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将csv文件读取到熊猫数据框中时遇到困难.我是熊猫的新手,这阻碍了我的进步.我已经阅读了文档并搜索了解决方案,但是我无法继续.我已经尝试了以下方法,但无济于事...

I'm having difficulty reading a csv file into the pandas data frame. I am a total newcomer to pandas, and this is preventing me from progressing. I have read the documentation and searched for solutions, but I am unable to proceed. I have tried the following to no avail...

import pandas as pd
import numpy as np
pd.read_csv('C:\Users\rcreedon\Desktop\TEST.csv')
pd.read_csv("C:\Users\rcreedon\Desktop\TEST.csv")

以及带/不带引号的类似排列.

and similar permutations with/without quotation marks.

它吐出一个大的复合错误,结尾是:

It spits out a large composite error that ends in:

IOError: File C:\Users
creedon\Desktop\TEST.csv does not exist

在错误中错过了"rcreedon"中的"r",这似乎很奇怪.这是引起问题的原因吗?

It seems strange that in the error it misses of the "r" from "rcreedon". Is this what's causing the problem?

为此,我也尝试过

pd.read_csv('C:\rcreedon\Desktop\TEST.csv')

当返回错误时,再次错过了'r'.

And again the 'r' was missed when the error was returned.

很抱歉成为这样的笨蛋,但我在这里苦苦挣扎....

Sorry to be such a block head, but I'm struggling here....

任何帮助表示赞赏.

推荐答案

"\ r"通常解释为特殊字符,表示回车.您可以在字符串文字中添加一个'r'前缀,以防止对该特殊序列进行解释(例如path = r"foo\rar"),或者,如已经建议的那样,仅使用常规斜杠作为路径定界符即可. Python足够智能,因此也可以在Windows上运行:-)

"\r" usually is interpreted as a special character and means carriage return. Either add a 'r' prefix to your string literals which prevents this special sequence from being interpreted (e.g. path = r"foo\rar"), or, as already suggested, just use a normal slash as path delimiter. Python is intelligent enough for it to also work on Windows :-)

这篇关于'CSV不存在'-Pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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