Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of dealing with Excel data in Python

Shulou Source: shulou.com Published: 2022-06-03 06:04:27 09月26日 Update

Excel data processing of Python

one。 Background.

In the work of operation and maintenance, colleagues or technical leaders may be encountered to provide metadata for Excel data, data extraction and collection, or automation of operation and maintenance. For the above scenarios, we need to carry out python processing.

II. Introduction of Xlrd module

2.1 read Excel

Xlrd in Python language reads excel table data, supports excel tables in xlsx and xls formats, and is an extension tool for reading Excel. I can only read it.

2.2 write Excel

If you write, use xlwt, meaning: the xls file write is written to the library.)

You can specify the table and the reading of the specified cell.

2.3 python3 tripartite module installation method: pip3 install xlrd, module import method: import xlrd

three。 Python reads Excel practical script

3.1 original Excel data format

3.2 python read the excel code section

Def readExcel (): import xlrd workbook=xlrd.open_workbook (excel rows rows devopsapap.xls') sheet_name = workbook.sheet_names () sheet = workbook.sheet_by_index (0) # sheet index starts at 0 [] rows = sheet.row_values (0) for i in list (range (2) Sheet.nrows): machineInfo=sheet.row_values (I) if machineInfo [2] = "ptest": data.append (machineInfo) return data resultData=readExcel () print (resultData)

Tags: Data module processing method format table tripartite code unit colleague scene actual combat tool meaning technology data processing file index background script Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Huawei OPPO Reno Docker Shulou Technology