In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article editor for you detailed introduction of "python how to read excel table", the content is detailed, the steps are clear, the details are handled properly, I hope this "python how to read excel table" article can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge.
Note before reading: Python third-party library support
Xlwt and xlrd libraries are required.
Data table creation and data writing
Xlwt is used to create and write data to excel. For more information, please see the following code comments:
Import xlwt # introduces the xlwt library workbook = xlwt.Workbook (encoding='utf-8') # to create a workbook and set it to code as utf-8worksheet = workbook.add_sheet ('course schedule') # create a sheet and name it course schedule # Zero is the first number in a computer, so the first line that humans understand should be the zeroth line for a computer Column is the same as worksheet.write (0,1, 'Monday') # write "Monday" worksheet.write (0,2,5) in the first row and second column # write 5worksheet.write (0,3,7) worksheet.write (0,4, xlwt.Formula ('SUM (C1) D1) # write the function SUM (C1) in the first row and the fifth column D1) workbook.save ('class schedule .xls') # Save this workbook And named it course schedule .xls.
Data table reading
Xlrd is mainly used to read Excel data. For more information, please see the notes below:
Import xlrd # introduce the xlwt library workbook = xlrd.open_workbook ('course schedule .xls') # Open a file called course schedule .xls worksheet = workbook.sheet_by_name ('course schedule') # Open the file called course Table sheetnrows = worksheet.nrows # get the valid number of rows in the sheet row = worksheet.row (0) # get all the numbers with a row index of 0 (that is, the first row) According to and return ncols = worksheet.ncols # to get the number of valid columns of the list col = worksheet.col (3) # get all the data with a column index of 3 (that is, the fourth column) and return print as a list (nrows Ncols) print (row, col) cell = worksheet.cell (0,1) # get row index 0 Data print (cell) for the cell with column index 1 (that is, the first row and the second column)
Office automation
With the blessing of the above two libraries, it provides conditions for the realization of office automation. We know that to use excel for office work is to use excel for data processing, and there are similarities in many data operations. For example, if you import data in bulk from a table, you can use python to read and write to the database at the same time. Because loops can be used for batch operations, python can automate data operations as long as the process is designed. In addition, there are many methods not introduced in these two libraries, and there are also some excellent excel libraries waiting for readers to dig. With these libraries, python Automation has a lot more to do.
Read here, this "python how to read excel table" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.