Home > Backend Development > Python Tutorial > Two ways to read Excel files

Two ways to read Excel files

little bottle
Release: 2019-04-09 13:37:05
forward
3448 people have browsed it

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template