1

I have noticed that when we set some options for pandas DataFrames such as pandas.DataFrame('max_rows',10) it works perfectly for DataFrame objects.

However, it has no effect on Style objects.

Check the following code :

import pandas as pd
import numpy as np

data= np.zeros((10,20))

pd.set_option('max_rows',4)
pd.set_option('max_columns',10)
df=pd.DataFrame(data)

display(df) 
display(df.style)

Which will result in : Result

I do not know how to set the properties for Styler object.

0

2 Answers 2

2

Styler is developing its own options. The current version 1.3.0 of pandas has not got many. Perhaps only the styler.render.max_elements.

Some recent pull requests to the github repo are adding these features but they will be Stylers own version.

Sign up to request clarification or add additional context in comments.

2 Comments

I see, First of all, thank you so so much, I have been trying to figure this out for the whole day. I think styler.render.max_elements is better than nothing. However, I am trying to change write a function to change the html code that basically does the same thing as max_row and max_column. Not sure if I'll be successfully. @Attack68
hey @Attack69, I found a way to mimic set_option(max_row) and set_option(max_columns) for styler objects. Though might be of your interest.
1

As @attack69 mentioned, styler has its own options under development. However, I could mimic set_option(max_row) and set_option(max_columns) for styler objects. Check the following code:

import pandas as pd
import numpy as np

data= np.zeros((10,20))
mx_rw=4
mx_cl=10
pd.set_option('max_rows',mx_rw)
pd.set_option('max_columns',mx_cl)
df=pd.DataFrame(data)

display(df) 
print(type(df))


df.loc[mx_rw/2]='...'
df.loc[:][mx_cl/2]='...'

temp=list(range(0,int(mx_rw/2),1))
temp.append('...')
temp.extend(range(int(mx_rw/2)+1,data.shape[0],1))
df.index=temp
del temp

temp=list(range(0,int(mx_cl/2),1))
temp.append('...')
temp.extend(range(int(mx_cl/2)+1,data.shape[1],1))
df.columns=temp
del temp

df=df.drop(list(range(int(mx_rw/2)+1,data.shape[0]-int(mx_rw/2),1)),0)
df=df.drop(list(range(int(mx_cl/2)+1,data.shape[1]-int(mx_cl/2),1)),1)
df=df.style.format(precision=1)

display(df)
print(type(df))

which both DataFrame and Styler object display the same thing. Result

2 Comments

this will prevent global styler methods such as highlight_max over a column from working. But the render trimming in development for pandas 1.4.0 will allow trimmed dataframes but with still valid styling
That is very true, however, I am using what you mentioned in the other question to modify each cell using HTML code basically. even for a simple data. The main problem is, it is not very efficient and takes more time. I just like the freedom of HTML coding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.