All,
I am trying to see how to style a row in a dataframe. There are several topics on this question (Styling dataframe, Styling a row in a dataframe). However, I am unable to find any of the answers satisfactory. Here is an example:
import numpy as np
import pandas as pd
import streamlit as st
def make_closest_station_id_global():
global i
i = 2
def highlight(x):
c1 = 'background-color: red'
c2 = 'background-color: white'
checklist = df['A'] == i
df1 = pd.DataFrame(np.where(checklist, c1, c2), index=x.index, columns=x.columns)
return df1
# Create a table to be styled in various ways
np.random.seed(24)
df = pd.DataFrame({"A": np.linspace(1, 5, 5)})
df = pd.concat([df, pd.DataFrame(np.random.randn(5, 4), columns=list("BCDE"))], axis=1)
df.iloc[0, 2] = np.nan
df.style.apply(highlight, axis=None)
st.header("Streamlit Testing")
st.dataframe(df)
I want to keep the row number dynamic based on a condition and I don’t see how to pass that to highlight ?