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 :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Display the Pandas DataFrame in table style
- Display the Pandas DataFrame in Heatmap style
- How to widen output display to see more columns in Pandas dataframe?
- How to display bar charts in Pandas dataframe on specified columns?
- Dealing with Rows and Columns in Pandas DataFrame
- Iterating over rows and columns in Pandas DataFrame
- Get the number of rows and number of columns in Pandas Dataframe
- How to create an empty DataFrame and append rows & columns to it in Pandas?
- Find maximum values & position in columns and rows of a Dataframe in Pandas
- Select first or last N rows in a Dataframe using head() and tail() method in Python-Pandas
- Count the number of rows and columns of a Pandas dataframe
- Count the number of rows and columns of Pandas dataframe
- Python | Delete rows/columns from DataFrame using Pandas.drop()
- How to randomly select rows from Pandas DataFrame
- How to get rows/index names in Pandas dataframe
- Get all rows in a Pandas DataFrame containing given substring
- Different ways to iterate over rows in Pandas Dataframe
- Selecting rows in pandas DataFrame based on conditions
- How to iterate over rows in Pandas Dataframe
- Sorting rows in pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

