python 中使用pandas读写excel文件

import pandas as pd

#使用pandas读取excel文件
xls_file=pd.ExcelFile('./data/workbook.xls')
xls_file.sheet_names#显示出读入excel文件中的表名字
table1=xls_file.parse('first_sheet')
table2=xls_file.parse('second_sheet')

xlsx_file=pd.ExcelFile("./demo.xlsx")
x1=xlsx_file.parse(0)
x2=xlsx_file.parse(1)

#excel文件的写出
#data.to_excel("abc.xlsx",sheet_name="abc",index=False,header=True)  #该条语句会运行失败,原因在于写入的对象是np数组而不是DataFrame对象,只有DataFrame对象才能使用to_excel方法。

DataFrame(data).to_excel("abc.xlsx",sheet_name="123",index=False,header=True)

#excel文件和pandas的交互读写,主要使用到pandas中的两个函数,一个是pd.ExcelFile函数,一个是to_excel函数


    原文作者:守护者20091776
    原文地址: https://www.jianshu.com/p/b5e8eab578bd
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞