[英]'DataFrame' object has no attribute 'tolist' when I try to convert an excel file to a list
I am trying to Read this excel file on my laptop which has only one column and I wish to transfer it to a list by pandas using:我正在尝试在我的笔记本电脑上阅读此 excel 文件,该文件只有一列,我希望使用 pandas 将其传输到列表中:
years = pd.read_excel(r"/Users/vijayaswani/Downloads/years.xlsx").tolist()
but I get the error但我得到了错误
'DataFrame' object has no attribute 'tolist'
This is weird for me because I had a csv file earlier which I used pretty much the same code to read and transfer to a list and it works fine.这对我来说很奇怪,因为我之前有一个 csv 文件,我使用几乎相同的代码来读取和传输到列表,它工作正常。
What is wrong with this code and how can I get this excel file in a list?此代码有什么问题,如何在列表中获取此 excel 文件?
(My ultimate goal is to get a list which I can transfer to a Tkinter Combobox) (我的最终目标是获得一个可以转移到 Tkinter 组合框的列表)
You might have a data frame with one column.您可能有一个包含一列的数据框。 Try
squeeze()
to coerce it to a pandas Series:尝试
squeeze()
将其强制为 pandas 系列:
years = (pd.read_excel(r"/Users/vijayaswani/Downloads/years.xlsx")
.squeeze()
.tolist())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.