读
import pandas as pd
filename="try.xlsx"//文件路径
try_data=pd.read_excel(filename)
first way
//遍历
data=[]
for i in try_data["data"]:
data.append(i)
second way
data=try_data.iloc[1:,0]//切片:[行数起始位置,列数]
写
xlwt
import xlwt
book=xlwt.Workbook(encoding="utf-8",style_compression=0)//编码方式
sheet=book.add_sheet("sheet1",cell_overwrite_ok=True)//sheet名称及是否可写
for i in range(len(g)):
sheet.write(i,0,g[i])//write(列数,行数,数值)
savepath="temp.xlsx"//保存路径
book.save(savepath)
openpyxl
import openpyxl
wb=openpyxl.Workbook()
ws=wb.active
ws.append(pre_A2)
wb.save(pre_GDP_filename)
|