pandas “如果不为 io 传递缓冲区或路径,则必须明确设置引擎”在 Panda 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42950045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:15:42  来源:igfitidea点击:

"Must explicitly set engine if not passing in buffer or path for io" in Panda

pythonpandasvalueerror

提问by JohnAndrews

When running the following Python Panda code:

运行以下 Python Panda 代码时:

    xl          = pd.ExcelFile(dataFileUrl)
    sheets      = xl.sheet_names
    data        = xl.parse(sheets[0])
    colheaders  = list(data)

I receive the ValueError:

我收到 ValueError:

Must explicitly set engine if not passing in buffer or path for io

The file is for sure an excel file, no doubt about that.

该文件肯定是一个 excel 文件,这一点毫无疑问。

What is happening?

怎么了?

回答by Stael

I would try

我会尝试

xl = pd.ExcelFile(dataFileUrl, engine='xlrd')

回答by Aaron Highsmith

I had this same problem and it was because the code that generated dataFileUrl produced a list with only one element in it. Changing to dataFileUrl[0] fixed the problem.

我遇到了同样的问题,这是因为生成 dataFileUrl 的代码生成了一个只有一个元素的列表。更改为 dataFileUrl[0] 解决了该问题。

回答by Stuti Verma

If you give your file path as:

如果您将文件路径指定为:

#Read and write to excel
dataFileUrl = R"D:\real_names.xlsx"
data = pd.read_excel(dataFileUrl)

it will possibly work. I have tried and tested.

它可能会起作用。我已经尝试并测试过。