In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to achieve Excel office automation in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The special processing here is mainly related to the date format data processing and commonly used aggregate data statistical processing, which can effectively achieve your common statistical requirements. The code is as follows:
# Statistics on the male-to-female ratio of employees def get_sex_percent (): sexlist= [] for rows in range (table.nrows-1): sexlist.append (table.cell (rows+1,2) .value) print (sexlist) print ("the male to female is:", round (sexlist.count ("male") / sexlist.count ("female", 2)) the output is: ['male', 'female', 'male' 'male', 'female', 'female', 'male', 'male', 'female', 'male' The male to female ratio is: 2.3 processing of time data type def get_date (): for rows in range (table.nrows): for cols in range (table.ncols): if (table.cell (rows,cols) .ctype = = 3): date=xlrd.xldate_as_datetime (table.cell (rows,cols). Value 0) print (date) # the last column of data statistical processing def get_statics (): sum=0 list1= [] for rows in range (table.nrows-1): sum+=int (table.cell (rows+1,table.ncols-1) .value) list1.append (int (table.cell (rows+1,table.ncols-1) .value) # print (table.cell (rows+1,8) .value) print ("the sum is:" Sum) # Sum print ("the avg is:", round (sum / table.ncols, 2)) # take the average print ("the max is:", sorted (list1) [- 1]) # take the maximum value print ("the min is:", sorted (list1) [0]) # take the minimum value if (len (list1)% 2): # determine whether the list length is odd or even Fetch the median print ("the median is:", (list1 [int (len (list1) / 2)] + list1 [int (len (list1) / 2x1)] / 2) else: print ("the median is:", list1 [int ((len (list1) + 1) / 2)])
If _ _ name__ = ='_ main__': get_date () get_statics ()
The code execution effect of the above two methods is as follows:
The above is the editor for you to share the Python how to achieve Excel office automation, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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.