Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count number of values
#1
Hello,

How would I go about reading ws1 column F starting at row 4 and counting the number of times the value 0 occurs and then write that number to ws3 column M row 2?


import openpyxl as xl; 
import os


input_dir = 'C:\\work\\comparison\\NNM'
template = 'C:\\work\\comparison\\template.xlsx'
summary = 'C:\\work\\comparison\\summary.xlsx'
newFile = 'Comparison.xlsx'




files = [file for file in os.listdir(input_dir)
         if os.path.isfile(file) and file.endswith(".xlsx")]


wb3 = xl.load_workbook(template) 
ws3 = wb3.worksheets[0] 

i=0
ii=0


for file in files: 
   input_file =  os.path.join(input_dir, file)
   wb1=xl.load_workbook(input_file)
   ws1=wb1.worksheets[0]

   
   wb2 = xl.load_workbook(summary) 
   ws2 = wb2.worksheets[1]

    
   ws3[f'A{i+2}']=ws1['A1'].value[28:]
   ws3[f'D{i+2}']=ws1['B4'].value
   ws3[f'E{i+2}']=ws1['D4'].value
   ws3[f'I{i+2}']=ws1['B'][-1].value
   ws3[f'J{i+2}']=ws1['D'][-1].value
   ws3[f'O{i+2}']=ws1['E'][-1].value 
   ws3[f'N{i+2}']=ws2[f'I{ii+6}'].value   
   i += 1
   ii +=1          
   
   

   wb3.save(newFile)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  find the sum of a series of values that equal a number ancorte 1 1,091 Oct-30-2023, 05:41 AM
Last Post: Gribouillis
  Row Count and coloumn count Yegor123 4 2,632 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  Unable to count the number of tries in guessing game. Frankduc 7 3,054 Mar-20-2022, 08:16 PM
Last Post: menator01
  Problem : Count the number of Duplicates NeedHelpPython 3 7,095 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  How can I count values between range dates ? Eidrizi 2 3,162 Mar-17-2021, 01:26 PM
Last Post: Eidrizi
  Count number of occurrences of list items in list of tuples t4keheart 1 3,093 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  Count the number of items in a nested list iofhua 2 5,167 Jun-07-2019, 06:47 PM
Last Post: iofhua
  count unique values of a list with a list 3Pinter 2 5,794 Jul-05-2018, 11:52 AM
Last Post: 3Pinter
  To count a number of strings in a txt file with python jpeich 5 9,578 Apr-29-2017, 05:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020