ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Python逐行写入excel

2021-01-29 23:59:26  阅读:55  来源: 互联网

标签:Python excel DataFrame filename pd import data 逐行


参考自博客

// An highlighted block
import xlsxwriter as xw
import pandas as pd
import openpyxl as op
import numpy as np

orderIds = [1,2,3]
items = ['A','B','C']
mydata = [10,20,30]
testData = [orderIds,items,mydata]
filename = '测试.xlsx'
def pd_toexcel(data,filename): # pandas库储存数据到excel
    dfData = { # 用字典设置DataFrame所需数据
        '序号':data[0],
        '项目':data[1],
        '数据':data[2]
    }
    df = pd.DataFrame(dfData) # 创建DataFrame
    print(df)
    df.to_excel(filename,index=False) # 存表,去除原始索引列(0,1,2...)
pd_toexcel(testData,filename)

标签:Python,excel,DataFrame,filename,pd,import,data,逐行
来源: https://blog.csdn.net/weixin_47211897/article/details/113408791

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有