4

I am working with a very big data set (18000 rows of data) which I only want to show a couple of rows such as 5 or 10 first rows. I was trying to use pandas.DataFrame().head(10) method but I am doing some styling and formatting and I receive the following error:

AttributeError: 'Styler' object has no attribute 'head'

This is how the styling looks like:

df.style.set_table_styles([{'props': [('font-size', '9pt'), 
                                            ('line-height', '100%')]}])

What is the best solution to this?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Arad Haselirad
  • 314
  • 2
  • 13

2 Answers2

3

I actually figured I could use the .head() method before assigning the styling to the data frame as follows:

df_ = df.head(10).style.set_table_styles([{'props': [('font-size', '9pt'), 
                                            ('line-height', '100%')]}])
df_

This worked quit well. Thank you for the comments.

Arad Haselirad
  • 314
  • 2
  • 13
2

If you have a df that is already styled (of type pandas.io.formats.style.Styler), you can export the style, select head (using .data to access pandas.core.frame.DataFrame object), and then reuse the style:

style = df.export()
df.data.head(10).style.use(style)
m7s
  • 103
  • 1
  • 6