python中的列表数据如何保存到excel

时间:2026-02-14 02:29:06

1、安装Pandas:

通过Python环境自带的Pip包管理工具就可以安装Pandas模块,命如下:

$ pip install pandas

pandas 模块操作excel依赖xlwt模块,所以也必须安装:

$ pip install xlwt 

具体如图

python中的列表数据如何保存到excel

python中的列表数据如何保存到excel

2、导入模块,python代码如下:

import pandas as pd

python中的列表数据如何保存到excel

3、创建一个python列表,并把列表转换为pandas的数据结构DataFrame类型,

python代码如下:

list=['value1','value2','value3']

dataframe = pd.DataFrame(list)

print(dataframe)

python中的列表数据如何保存到excel

4、将dataframe保存到excel文件中

python代码如下:

dataframe.to_excel('/home/list.xls')

python中的列表数据如何保存到excel

5、执行完成之后,会在保存指定目录,查看excel文件的内容

python中的列表数据如何保存到excel

python中的列表数据如何保存到excel

6、完整代码如下:

import pandas as pd

list=['value1','value2','value3']

dataframe = pd.DataFrame(list)

print(dataframe)

dataframe.to_excel('/home/hzd/list.xls')

© 2026 长短途
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com