Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.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/2/django/23.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中的ValueError_Python_Django_Pandas - Fatal编程技术网

Python 如何修复pandas中的ValueError

Python 如何修复pandas中的ValueError,python,django,pandas,Python,Django,Pandas,我正在将一个应用程序从一个经典的Tkinter GUI移动到一个基于Django云的应用程序,并收到一个 ValueError:无效的文件路径或缓冲区对象类型: 当尝试运行调用pandas的函数时 异常位置:C:\Users\alfor\AppData\Local\Programs\Python\Python37-32\lib\site packages\pandas\io\common.py在get\u filepath\u或\u buffer中,第232行 我没有尝试太多,因为我在搜索中找不

我正在将一个应用程序从一个经典的Tkinter GUI移动到一个基于Django云的应用程序,并收到一个

ValueError:无效的文件路径或缓冲区对象类型:

当尝试运行调用pandas的函数时

异常位置:C:\Users\alfor\AppData\Local\Programs\Python\Python37-32\lib\site packages\pandas\io\common.py在get\u filepath\u或\u buffer中,第232行

我没有尝试太多,因为我在搜索中找不到相同的错误

我不相信这个功能会运行,因为我的媒体文件夹没有一个新的目录来保存文件。。但我可能错了

出现问题的函数的开头如下所示:

def runpayroll():
    man_name = 'Jessica Jones'

    sar_file = os.path.isfile('media/reports/Stylist_Analysis.xls')
    sar_file2 = os.path.isfile('media/reports/Stylist_Analysis.xls')
    tips_file = os.path.isfile('media/reports/Tips_By_Employee_Report.xls')
    hours_wk1_file = os.path.isfile('media/reports/Employee_Hours1.xls')
    hours_wk2_file = os.path.isfile('media/reports/Employee_Hours2.xls')
    retention_file = os.path.isfile('media/reports/SC_Client_Retention_Report.xls')
    efficiency_file = os.path.isfile('media/reports/Employee_Service_Efficiency.xls')

    df_sar = pd.read_excel(sar_file,
                           sheet_name=0, header=None, skiprows=4)
    df_sar2 = pd.read_excel(sar_file2,
                            sheet_name=0, header=None, skiprows=4)
    df_tips = pd.read_excel(tips_file,
                            sheet_name=0, header=None, skiprows=0)
    df_hours1 = pd.read_excel(hours_wk1_file,
                              header=None, skiprows=5)
    df_hours2 = pd.read_excel(hours_wk2_file,
                              header=None, skiprows=5)
    df_retention = pd.read_excel(retention_file, sheet_name=0,
                                 header=None, skiprows=8)
    df_efficiency = pd.read_excel(efficiency_file, sheet_name=0,
                                  header=None, skiprows=5)

我在这个函数的其余部分中唯一更改的代码是这个,我假设它无关紧要,因为它只是一个文件位置

    writer = pd.ExcelWriter('/media/payroll.xlsx', engine='xlsxwriter')
我没有使用tkinter向用户询问文件保存位置,而是使用

    with open(file_path, 'rb') as f:
        response = HttpResponse(f, content_type=guess_type(file_path)[0])
        response['Content-Length'] = len(response.content)
        return response

预期的结果是打开几个excel工作表,对数据框做一些工作,并向用户吐出一个excel工作表。

我相信您需要更改以下每个文件:

sar_file = os.path.isfile('media/reports/Stylist_Analysis.xls')
致:

因为:

如果路径是现有的常规文件,则返回True。这遵循符号链接,因此对于同一路径,islink()和isfile()都可以为true


很好的解释!谢谢你!现在转到下一个错误!:D
sar_file = 'media/reports/Stylist_Analysis.xls'