How to batch process excel data in python?

coldplay.xixi
Release: 2020-06-15 11:09:42
Original
5573 people have browsed it

How to batch process excel data in python?

#How does python batch process excel data?

How to process excel data in batches with python:

The contents of excel need to be regular so that python can read them in order. For example, read by row and column.

1. Install the xlrd module

Go to the python official website to download the http://pypi.python.org/pypi/xlrd module and install it. The premise is that the python environment has been installed.

2. Introduction to use

1. Import module

import xlrd

2. Open Excel file to read data

data = xlrd.open_workbook('excelFile.xls')

3. Use skills

Get a worksheet

table = data.sheets()[0] #Get by index order

table = data.sheet_by_index(0) #Get by index order

table = data.sheet_by_name(u'Sheet1')#Get by name

Get the value of the entire row and column (array)

table.row_values( i)

table.col_values(i)

Get the number of rows and columns

nrows = table.nrows

ncols = table.ncols

Loop row list data

for i in range(nrows):

print table.row_values(i)

cell

cell_A1 = table.cell(0,0).value

cell_C4 = table.cell(2,3).value

Use row and column index

cell_A1 = table.row(0) [0].value

cell_A2 = table.col(1)[0].value

Simple write

row = 0

col = 0

# Type 0 empty, 1 string, 2 number, 3 date, 4 boolean, 5 error

ctype = 1 value = 'Cell value'

xf = 0 #Extended formatting

table.put_cell(row, col, ctype, value, xf)

table.cell(0,0) #The value of the cell'

table.cell(0,0).value #The value of the cell'

Recommended tutorial: "python video tutorial"

The above is the detailed content of How to batch process excel data in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!