0

I'm using FPDF to generate reports with charts so I was thinking about using conditionals to use predeterminated text depending on the results from the df['COLUMN'].value_counts() with something like this:

This is a df, with multi-index generated using a for with value.counts() for each column, so what I would like to do is depending if the counts as in the example in Semi-Auto is the highest count do something like this:

from fpdf import FPDF
from datetime import datetime, timedelta
import os

if biggest_value_from_counts is == Semi-Auto use:

   dummytext = "The most common transmission in the US is Semi-Auto becase blabla" + "\n"
   dummytext += "line 2" + "\n"
   dummytext += "line 3"
   ''' Second Page '''
   pdf.add_page()
   pdf.multi_cell(0, 5, dummytext)
   pdf.output(filename, 'F')

It is possible?

index   transmission
0   Automatic   22319
1   Manual  61308
2   Other   10
3   Semi-Auto   24903

enter image description here

  • 1
    `depending if the counts as in the example in Semi-Auto is the highest count do something like this:` What if it's not the highest count? Should it instead mention the one with the highest count? Should it say, e.g. "The second most common transmission in the US is Semi-Auto..." What about the other elements of this dataframe? Should the program loop over it and put a page for each type of transmission? – Nick ODell Oct 22 '22 at 16:30
  • 1
    PS: Can you include your data in a text format, instead of an image? This saves people who want to help you from re-typing your data. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Nick ODell Oct 22 '22 at 16:32
  • 1.- if it's not the highest could be mentioned but will be elseif for this kind of things. 2.- The other elements in this dataframe will have a similar action I just need one example of how to do it. PD.- I added already –  Oct 23 '22 at 01:45

1 Answers1

0

df_index= df['columnname'].value_counts().idxmax()