Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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 3.5:OSError:[Errno 22]无效参数:';E:\\python\\Sales prog\nacinka.xlsx';_Python_Python 3.x_Pandas - Fatal编程技术网

python 3.5:OSError:[Errno 22]无效参数:';E:\\python\\Sales prog\nacinka.xlsx';

python 3.5:OSError:[Errno 22]无效参数:';E:\\python\\Sales prog\nacinka.xlsx';,python,python-3.x,pandas,Python,Python 3.x,Pandas,有一个很好的错误 import pandas as pd import xgboost as xgb sales_shop = pd.read_excel('E:\python\Sales prog\sales.xlsx', index_col = "date") holidays = pd.read_excel('E:\python\Sales prog\holidays common.xlsx', index_col = "date") datecom = pd.read_excel('E:

有一个很好的错误

import pandas as pd
import xgboost as xgb
sales_shop = pd.read_excel('E:\python\Sales prog\sales.xlsx', index_col = "date")
holidays = pd.read_excel('E:\python\Sales prog\holidays common.xlsx', index_col = "date")
datecom = pd.read_excel('E:\python\Sales prog\date.xlsx', index_col = "date")
nacenka = pd.read_excel('E:\python\Sales prog\nacenka.xlsx', index_col = "date")
错误文本:

OSError:[Errno 22]无效参数:“E:\python\Sales” prog\n存储库.xlsx'

但如果我写:

import pandas as pd
import xgboost as xgb
sales_shop = pd.read_excel('E:\python\Sales prog\sales.xlsx', index_col = "date")
holidays = pd.read_excel('E:\python\Sales prog\holidays common.xlsx', index_col = "date")
datecom = pd.read_excel('E:\python\Sales prog\date.xlsx', index_col = "date")
nacenka = pd.read_excel('E:/python/Sales prog/nacenka.xlsx', index_col = "date") 

我没有问题。。。但是怎么做呢?我只是改变了坡度,在其他人身上他保持不变

如果您必须多次使用变量,我建议您使用变量中的路径,并且您应该遵循注释中的建议,使用\n会给您带来很多麻烦,在我的情况下,使用windows,我必须避开所有的“\”

试试这个:

import pandas as pd
import xgboost as xgb
salesPath = "E:\\python\\Sales prog\\"
sales_shop = pd.read_excel(salesPath+'sales.xlsx', index_col = "date")
holidays = pd.read_excel(salesPath+'holidays common.xlsx', index_col = "date")
datecom = pd.read_excel(salesPath+'date.xlsx', index_col = "date")
nacenka = pd.read_excel(salesPath+'nacenka.xlsx', index_col = "date")

因为
\n
是一个被推断为换行符的控制字符,如果您在使用windows,您应该小心使用路径字符串。在文件名文本字符串前面加上
r
,例如
pd.read\u excel(r'e:\py…
我碰巧使用了r''或escape char。OSError:[Errno 22]无效参数:'\u202aY:\\filepath.xlsx'