成功解决AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘

成功解决AttributeError: 'DataFrame' object has no attribute 'tolist'

目录

解决问题

解决思路

解决方法


解决问题

return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'tolist'

解决思路

属性错误:“DataFrame”对象没有属性“tolist”

解决方法

切记,DataFrame没有tolist()方法,而series.Series有tolist()方法,故需要修改

import pandas as pd

#读取xls文件
file_path='data/test1226.xls'
data_frame_xls=pd.read_excel(file_path)
data_df01 = data_frame_xls[['age']]
print(type(data_df01))
print(res)

改为

import pandas as pd

#读取xls文件
file_path='data/test1226.xls'
data_frame_xls=pd.read_excel(file_path)
data_df01 = data_frame_xls[['age']]
print(type(data_df01))

data_df01 = data_frame_xls['age']
print(type(data_df01 ))
res = data_df01 .tolist()
print(res)

哈哈,大功告成!

你可能感兴趣的:(python)