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

时间:2024-10-15 03:53:41

1、安装Pandas:通过Python环境自带的Pip包管理工具就可以安装Pandas模块,命如下:$ pip install pandaspandas模块操作excel依赖xlwt模块,所以也必须安装:$ pip installxlwt具体如图

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

2、导入模块,python代码如下:import pandas as pd

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

3、创建一个python列表,并把列表转换为pandas的数据结构DataFrame类型,p鲻戟缒男ython代码如下:list=['value1刻八圄俏9;,'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 pdlist=['value1','value2','value3'稆糨孝汶;]dataframe = pd.DataFrame(list)print(dataframe)dataframe.to_excel('/home/hzd/list.xls')

© 手抄报圈