Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用pandas读取excel文件如何修复:FileNotFoundError(2,';没有这样的文件或目录';)_Python_Excel_Pandas - Fatal编程技术网

在python中使用pandas读取excel文件如何修复:FileNotFoundError(2,';没有这样的文件或目录';)

在python中使用pandas读取excel文件如何修复:FileNotFoundError(2,';没有这样的文件或目录';),python,excel,pandas,Python,Excel,Pandas,我的最终目标是从两列中获取数据,以便绘制和过滤数据,因此我尝试将该数据转换为数组。因此,我试图从excel电子表格中的两列导入数据,但pandas找不到该文件 #C:\Users\curti is my cwd df = pd.read_excel('\Desktop\My Undergrad Thesis\Raw Data Raw Nitrogen\Compiled Data - Raw (Nitrogen).xlsm', sheetname='2018_10_22_Test6') d

我的最终目标是从两列中获取数据,以便绘制和过滤数据,因此我尝试将该数据转换为数组。因此,我试图从excel电子表格中的两列导入数据,但pandas找不到该文件

 #C:\Users\curti is my cwd
 df = pd.read_excel('\Desktop\My Undergrad Thesis\Raw Data Raw Nitrogen\Compiled Data - Raw (Nitrogen).xlsm', sheetname='2018_10_22_Test6') 
 df.head()

 print('success')

我相信这是显而易见的,但我已经在网上找了一段时间,没有任何东西能解决它,所以如果有人能给我指出正确的方向,那就太好了!另外,如果有更好的方法来实现我的目标,请告诉我。

这里的问题与Python如何读取字符串有关,因此会影响文件输入

Python中的
\
是一种特殊字符,也称为转义字符,用于表示其他特殊字符,如
\n
\t
。例如,
\n
返回换行符。要实际打印反斜杠,您需要使用
\\

'\\Desktop\\My Undergrad Thesis\\Raw Data Raw Nitrogen\\Compiled Data - Raw (Nitrogen).xlsm'
或者也可以使用Python文档中描述的
'r'
文本:

字符串和字节文本都可以选择前缀为 字母“r”或“r”;这样的字符串称为原始字符串和treat 反斜杠作为文字字符。因此,在字符串文本中, 原始字符串中的'\U'和'\U'转义未被特殊处理。鉴于 Python2.x的原始unicode文本的行为与Python不同 3.x的“ur”语法不受支持


这里的问题与Python如何读取字符串有关,因此会影响文件输入

Python中的
\
是一种特殊字符,也称为转义字符,用于表示其他特殊字符,如
\n
\t
。例如,
\n
返回换行符。要实际打印反斜杠,您需要使用
\\

'\\Desktop\\My Undergrad Thesis\\Raw Data Raw Nitrogen\\Compiled Data - Raw (Nitrogen).xlsm'
或者也可以使用Python文档中描述的
'r'
文本:

字符串和字节文本都可以选择前缀为 字母“r”或“r”;这样的字符串称为原始字符串和treat 反斜杠作为文字字符。因此,在字符串文本中, 原始字符串中的'\U'和'\U'转义未被特殊处理。鉴于 Python2.x的原始unicode文本的行为与Python不同 3.x的“ur”语法不受支持


df=pd.read\u excel(r'C:\Users\curti\Desktop\My本科生论文\Raw Data Raw non\Compiled Data-Raw(non).xlsm',sheetname='2018\u 10\u 22\u Test6')
@Wen oh My gosh你是我的英雄@Curtis你应该仔细阅读
r'string'
的功能,这对于在代码中定义路径非常重要。
df=pd.read\u excel(r'C:\Users\curti\Desktop\My本科生论文\Raw Data Raw Non\Compiled Data-Raw(Non).xlsm',sheetname='2018\u 10\u 22\u Test6')
@Wen oh My gosh you is My hero@Curtis您应该仔细阅读
r'string'
的功能,这对于在代码中定义路径非常重要。