Python Forum
[openpyxl] Increment cells being pasted into Template
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[openpyxl] Increment cells being pasted into Template
#5
(Jul-16-2020, 11:24 AM)palladium Wrote: Hmm, maybe try using pandas to convert the range of cells you are interested in into a series, and then use the value_count() function to take it from there? Something like:

import pandas as pd

series = pd.read_excel(filename, sheetname, skiprows = [0:5],usecols = "F", squeeze = True) # I'll let you enter the filename and sheetname. Make sure squeeze is True so that you end up with a Series, not a dataframe. 
counts = series.value_counts()
z = counts[0]
...and then write z to the cell you want with openpyxl.

More info: https://pandas.pydata.org/pandas-docs/st...excel.html, https://pandas.pydata.org/pandas-docs/st...ounts.html

Credits: https://stackoverflow.com/questions/1220...e-variable

Hello,

This code doesn't work I end up this error message

counts = series.value_counts()

AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts'
Reply


Messages In This Thread
RE: [openpyxl] Increment cells being pasted into Template - by Kristenl2784 - Jul-16-2020, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help to increment a third list hermine 7 1,472 Nov-29-2022, 04:19 PM
Last Post: perfringo
  mysql id auto increment not working tantony 10 2,671 Oct-18-2022, 11:43 PM
Last Post: Pedroski55
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 10,200 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,396 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Character Increment AnokhiRaaz 1 2,548 Apr-22-2021, 04:29 AM
Last Post: buran
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 7,629 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Can you help me to merge the cells with OpenPyXL? TurboC 1 2,257 Feb-01-2021, 12:54 AM
Last Post: Larz60+
  Increment text files output and limit contains Kaminsky 1 3,319 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  Increment formula Kristenl2784 4 3,003 Jul-20-2020, 10:14 PM
Last Post: Kristenl2784
  Copy certain cells into new workbook certain cells Kristenl2784 4 2,562 Jul-14-2020, 07:59 PM
Last Post: Kristenl2784

Forum Jump:

User Panel Messages

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