Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of dealing with Excel data in Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report