Home >Backend Development >Python Tutorial >Two ways to read Excel files
This article is about the specific code of two ways of reading Excel files in Python. Interested friends can try it!
1. Reading operation of Pandas library
from pandas import read_excel
dr=read_excel(filename,header)
dr#dataframe data
dw=DataFrams(data=dict,columns=dict.keys())
dw.to_excel(filename)
2. xlrd/xlwt
2.1. xlrd——Read
work_book=xlrd.open_workbook(filename)
sheet1=work_book.sheet_by_name('Sheet1' )
#shee1=work_book,sheet_by_index(0)
sheet1.cell_value(row,col)
sheet1.row(i) #Return a list, the content is data type : Dictionary of data content;
sheet1.row_values(i)#Returns the data content of row i
sheet1.col(i)
sheet1.col_values(i)
2.2, xlwt——Write
dw=xlwt.Workbook()
sheet_1=dw.add_sheet('sheet1',cell_overwrite_ok=True)
sheet_1.write(row,col,string)
dw.save(filename)
[Recommended course: Python video tutorial]
The above is the detailed content of Two ways to read Excel files. For more information, please follow other related articles on the PHP Chinese website!