I have to admit that my question and its title were incorrectly set and I have to close this topic:
pt.style.format({'percent_on_rent': '{:.0%}'})
code line in my code snippet returns pandas Styler object instance linked to its parent pandas DataFrame object instance. AFAIU when Jupiter Notebook code cell with such a code is run then Jupiter Notebook captures pandas Styler object instance and immediately formats it for output under the running cell while
print(pt)
prints pandas DataFrame object instance and how this object instance string(?) representation is obtained by the print(...) Python method and sent to standard(?) output and this standard output captured by Jupiter Notebook and rendered under the cell where the code is running can be probably found only in the Jupiter Notebook sources.
Writing and running in a Jupiter Notebook cell the following code:
my_styler = pt.style.format({'percent_on_rent': '{:.0%}'})
my_styler
would be equivalent to just
pt.style.format({'percent_on_rent': '{:.0%}'})
while
my_styler = pt.style.format({'percent_on_rent': '{:.0%}'})
print(my_styler)
would output
<pandas.io.formats.style.Styler object at 0x...>
Here is a link on a topic of using pandas Styler object in Jupiter Notebook. More information could be googled.
Please correct me if I'm still wrong in this explanation.
Thanks!
[Update]
Here is a sample code, which demonstrates how to return pandas Styler object instance from Python methods and then output them in Jupiter Notebook using display(...) method:
import numpy as np
import pandas as pd
def rc1():
return np.random.choice(['benzine', 'diesel', 'electro'])
def rc2():
return 1 if np.random.choice([True, False]) else 0
def test_pandas_styler(caption):
# fill list
data = []
for i in range(21): data.append([rc1(), rc2()])
# make data frame
df = pd.DataFrame(data, columns = ['engine_type', 'rented'])
# make pivot table
pt = df.pivot_table(index=['engine_type'], values= ['rented'], aggfunc=[np.mean]).reset_index()
pt.set_axis(['engine type', 'percent on rent'], axis = 'columns', inplace = True)
# style pivot table
st = pt.style.format({'percent on rent': '{:.0%}'}).hide_index()
st.set_table_styles([
dict(selector="th", props=[('color', 'darkblue'),
('vertical-align', 'top')]),
dict(selector="th:first-child", props=[('max-width', '70px'), ('text-align', 'left')]),
dict(selector="th:last-child", props=[('max-width', '50px')]),
dict(selector="td:first-child", props=[('text-align', 'left')])
])
st.caption = caption
return st
for f in [test_pandas_styler('Test {}'.format(i)) for i in range(1,4)]:
display(f)

pandas - df.style.format() having no effect on dataframe - Stack Overflow
.style.format not working in dataframe column
Styler class doesn't apply formatting from Styler.format when writing to Excel
python - problem of format while using pandas style - Stack Overflow
I am trying to add a '+' in front of positive numbers in one of the column in my dataframe. There are already negative numbers and zeros in the column. The column represents position changes and is automatically updated every 24hrs. Someone suggested I try the following -
df2.style.format({'Position Change':"{0:+g}"})
df2 is the name of the dataframe and Position Change is the name of the column. When I add the suggested code it does not change anything in the column, it also does not raise an error, so nothing happens. Can anyone help or know of another way to add + in front of a positive number in a column on a dataframe without doing it manually. Thanks