amn41  
                
                  
                    March 20, 2020,  4:58pm
                   
                  1 
               
             
            
              I’m trying to render a dataframe in my app and highlight a particular row.
There’s a stackoverflow answer for this https://stackoverflow.com/questions/50100635/highlight-color-a-panda-data-frame-row-by-index 
but this involves calling the apply method, which as far as I understand it actually does the rendering, when what I want is to modify the Styler object so I can pass it to streamlit as shown here 
How do i do that?
             
            
              
                
            
           
          
            
            
              Hi @amn41 ,
Welcome to the forum 
The second example in the dataframe docs that you referenced shows how to style cells.
You can also pass a Pandas Styler object to change the style of the rendered DataFrame:
>>> df = pd.DataFrame(
...    np.random.randn(10, 20),
...    columns=('col %d' % i for i in range(20)))
...
>>> st.dataframe(df.style.highlight_max(axis=0))
Here are some additional examples
  
  
    
# -*- coding: utf-8 -*-
# Copyright 2018-2020 Streamlit Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import streamlit as st
import pandas as pd
import numpy as np
show original 
   
  
    
    
  
  
 
  
  
    
# -*- coding: utf-8 -*-
# Copyright 2018-2020 Streamlit Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Adapted from https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
"""
import numpy as np
show original 
   
  
    
    
  
  
 
             
            
              2 Likes