1

How to make column names Bold in Pandas Data-frame while highlighting the Header.

Datatframe Below..

Name        Sir Name    Country Age
James       Pullman     Holland 38
Ricardo     Jacob       Holland 28
Arie        Tilman      Holland 27
Ruben       Juneja      Holland 29
Naveen      Therry      Holland 26
Audery      Cuenin      Holland 27

Expected:

enter image description here

OR

Fill the color to the whole background

enter image description here

user2023
  • 452
  • 5
  • 22
  • 1
    Would appreciate any comment before someone place a minus vote? – user2023 Mar 15 '20 at 09:01
  • I'm not entirely sure if this what you were asking, but I provided an example below, if this is what you are asking, – David Erickson Mar 15 '20 at 09:03
  • Thanks David, i perceive that it makes column names bold, however i want to highlight the column name header. – user2023 Mar 15 '20 at 09:05
  • I think here is necessary set css in style object. – jezrael Mar 15 '20 at 09:07
  • @jezrael, thanks for the making it duplicate, but i show this links. and another https://stackoverflow.com/questions/57805803/how-to-to-add-background-color-to-a-specific-column-of-pandas-dataframe-and-save/57806265#57806265 but i did nit get it how to do it .. just learning around, i have edited the question before you marked it duplicate. – user2023 Mar 15 '20 at 09:10
  • 1
    @kulfi - yes, only change `css` to bold, it is problem? – jezrael Mar 15 '20 at 09:11
  • I need to highlight the whole column header as well. if you can guide that will be good. – user2023 Mar 15 '20 at 09:13
  • Edited my question, may be that will helpful to get some answer. – user2023 Mar 15 '20 at 09:17
  • @kulfi - OK, do you test solution from dupe? It is what you need? – jezrael Mar 15 '20 at 09:22
  • i did `s = df.style.set_table_styles([{ 'selector': 'th', 'props': [('background-color', 'yellow'), ('color', 'cyan')]}])` when i did `print(s)` i get `` . i did not get table printed. – user2023 Mar 15 '20 at 10:01

1 Answers1

0

@kulfi, either 1) it is not a dataframe or 2) you are using print. I coded an example of the data below. If you copy and paste this it will be bolded. Notice how I just type df instead of print(df). If you use other common features such as pd.read_csv('filename.csv'), then it will automaticlly be imported as a dataframe. Not sure what the issue is for you, but I hope this helps:

import pandas as pd
df = pd.DataFrame({'Name': ['James', 'Ricardo', 'Aire'],
                   'Sir' : ['Pullman', 'Jacob', 'Tilman']})
df

enter image description here

David Erickson
  • 16,433
  • 2
  • 19
  • 35
  • Thank you @David for the hint and placing an answer.. +1 for the support and way around – user2023 Mar 15 '20 at 09:01
  • No problem @Kulfi -- what was the specific problem for you? Was it 1) 2) or something else? I would like to point you to some good resources depending on your answer. – David Erickson Mar 15 '20 at 09:04
  • many thanks for your inputs and answer, i have updated the qustion , sorry for making confusion but your answer make my doubt clear. – user2023 Mar 15 '20 at 09:14