简体   繁体   English

当我尝试将 excel 文件转换为列表时,“DataFrame”object 没有属性“tolist”

[英]'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.

相关问题 当我尝试将 JSON 转换为 Pandas Dataframe 时出现错误“AttributeError: 'list' object has no attribute 'values'” - The error "AttributeError: 'list' object has no attribute 'values'" appears when I try to convert JSON to Pandas Dataframe Bokeh:AttributeError:'DataFrame'对象没有属性'tolist' - Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist' AttributeError:“ DataFrame”对象没有属性“ tolist” - AttributeError: 'DataFrame' object has no attribute 'tolist' 获取“列表”object 在 python 中没有属性“tolist” - Getting 'list' object has no attribute 'tolist' in python 错误:当我尝试从CSV文件中拆分行时,“列表”对象没有属性“拆分” - Error: 'list' object has no attribute 'split' when i try to split a row from csv file AttributeError: 当我尝试从 csv 文件中拆分一行时,“列表”对象没有属性“拆分” - AttributeError: 'list' object has no attribute 'split' when i try to split a row from csv file 熊猫数据框到 excel: AttributeError: 'list' 对象没有属性 'to_excel' - Pandas dataframe to excel: AttributeError: 'list' object has no attribute 'to_excel' 拆分 dataframe 的每一行并变成 excel 文件 - 'list' object 没有属性 'to_frame error' - Split each line of a dataframe and turn into excel file - 'list' object has no attribute 'to_frame error' AttributeError:当我尝试在python中运行API请求时,“ list”对象没有属性“ get” - AttributeError: 'list' object has no attribute 'get' when I try running my API request in python 如何修复AttributeError:当我尝试替换csv读取中的某些文本时,“列表”对象没有属性“替换” - How to fix AttributeError: 'list' object has no attribute 'replace' when I try to replace some text in a csv read
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM