0

I have a dataframe that i am trying to format certain cell values/the row where the cell value != 0. I am ONLY looking at rows 2 and 3 based off the index (the last two rows) so I only want the condition and formatting to apply to the last two rows. Ideally, i would only like to highlight a cell under the Findings column but highlighting the row also works.

This is what my data frame looks like

i'd like to find a condition where if ID and name check findings are ever != 0, i want that row or even just the findings cell to be red to alert me that there is an issue with the data.

Is that possible to do? I am struggling to find a way to update the specific cell value or row to RED instead of a specific column?

The condition is like 
if check == 'ID Check' and findings != 0:
 [code to make cell value/row red] 
elif check == 'Name Check' and findings != 0:
  [code to make cell value/row red] 
else [default color?]

the data frame is built like this:

def record_count():
    with open('filename.csv', encoding='utf8') as file:
        record_number = len(list(file))
        print("Number of records on file:", record_number)
        return record_number


def user por_count():
    df = pd.read_csv(filename.csv', low_memory=False)
    user_number = df['users'].nunique()
    print("Number of users on file:", str(users))
    return users


def id_check():
    df = pd.read_csv('filename.csv', low_memory=False)
    missing_id = df["id"].isna().sum()
    print("Number of users missing an id:", missing_id)
    return missing_id

def name_check():
    df = pd.read_csv('filename.csv', low_memory=False)
    missing_name = derivs["name"].isna().sum()
    print("Number of users missing a name:", missing_name)
    return missing_name

checks_table = {
    'Check' : ['Record Check', 'ID Check', 'Name Check'],
    'Summary' : ['Number of records on file','Number of records missing an ID', 'Number of users missing a name'],
    'Findings' : [record_count(), id_check(), name_check()]
}

df_checks = pd.DataFrame.from_dict(checks_table)
df_checks.head()
bananas
  • 133
  • 8
  • 1
    I think solution from dupe is possible use here, do you try it and not working? – jezrael Dec 06 '22 at 06:38
  • Hi jezrael, your solution for my last question worked https://stackoverflow.com/questions/74683815/how-to-make-dataframe-content-in-e-mail-go-red-in-html-based-off-results-using-p/74684340#74684340 but the issue is that i have more than one function in my dataframe now. I don't want the highlighting to happen to all the rows in my dataframe -- just the bottom two. I think adjustments need to be made but i'm not 100% sure how – bananas Dec 06 '22 at 07:00
  • 1
    Can you try change `.mask(x['Findings'].ne(0), 'color:red;'))` to `.mask(x['Findings'].ne(0) & df['Check'].isin(['ID Check','Name Check']), 'color:red;'))` ? – jezrael Dec 06 '22 at 07:28
  • YOU ARE LITERALLY THE MOST AMAZING PERSON EVER!! Thank you :) I updated my code to show your excellence – bananas Dec 06 '22 at 13:12

0 Answers0