使用pandas操作excel

# -*- coding: utf-8 -*-
'''
@File  : excel.py
@Author: qiguagnhui
@Date  : 2020-04-15 22:57
@Desc  :
'''

import pandas as pd
import time


start_time = time.time()


# 创建空的表
# df=pd.DataFrame()#构造原始数据文件
# df.to_excel('demo.xlsx')#生成Excel文件,并存到指定文件路径下


# 读取excel数据
# df = pd.read_excel('demo.xlsx')
# print(df.shape)
# print(df.columns)  # 行首
# print(df.head())  # 前五行数据
# print(df.tail())    #  末尾5行数据


# create some Pandas DateFrame from some data
df1 = pd.DataFrame({'name': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
df2 = pd.DataFrame({'age': [8, 9, 10, 11, 12, 13]})
df3 = pd.DataFrame({'address': [14, 15, 16, 17, 18]})
All = [df1, df2, df3]
# create a Pandas Excel writer using xlswriter
writer = pd.ExcelWriter('demo.xlsx')

# df1.to_excel(writer, startcol=1, index=False)
df1.to_excel(writer, index=False)
# df2.to_excel(writer, sheet_name='sheet1', startcol=1, index=False)
# df3.to_excel(writer, sheet_name='sheet1', index=False)

writer.save()


print(time.time()-start_time)

你可能感兴趣的:(使用pandas操作excel)