Monday, July 27, 2026
HomeLanguagesDisplay the Pandas DataFrame in table style and border around the table...

Display the Pandas DataFrame in table style and border around the table and not around the rows

Let us see how to style a Pandas DataFrame such that it has a border around the table. We will be using the set_table_styles() method of the Styler class in the Pandas module.

set_table_styles()

Syntax : set_table_styles(self, table_styles)

Parameters :
table_styles : List, each individual table_style should be a dictionary with selector and props keys.

Returns : Styler

Example 1 :




# import the module
import pandas as pd 
  
# create a DataFrame 
ODI_runs = {'name': ['Tendulkar', 'Sangakkara', 'Ponting'
                      'Jayasurya', 'Jayawardene', 'Kohli'
                      'Haq', 'Kallis', 'Ganguly', 'Dravid'], 
            'runs': [18426, 14234, 13704, 13430, 12650
                     11867, 11739, 11579, 11363, 10889]} 
df = pd.DataFrame(ODI_runs)  
  
# making a yellow border
df.style.set_table_styles([{'selector' : '',
                            'props' : [('border',
                                        '10px solid yellow')]}])


Output :

Example 2 :




# import the module
import pandas as pd 
  
# create a DataFrame 
df = pd.DataFrame({"A":[14, 4, 5, 4, 1], 
                    "B":[5, 2, 54, 3, 2],  
                    "C":[20, 20, 7, 3, 8], 
                    "D":[14, 3, 6, 2, 6]})
  
# making a green border
df.style.set_table_styles([{'selector' : '',
                            'props' : [('border',
                                        '2px solid green')]}])


Output :

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS