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?
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With