I'm working with pandas 0.18 in Jupyter.
I'd like to configure Jupyter/pandas to display 2 decimal places throughout, and to use comma separators in thousands.
How can I do this?
We use the python string format syntax '{:,. 0f}'. format to add the thousand comma separators to the numbers. Then we use python's map() function to iterate and apply the formatting to all the rows in the 'Median Sales Price' column.
In Python, to print 2 decimal places we will use str. format() with “{:. 2f}” as string and float as a number. Call print and it will print the float with 2 decimal places.
Lets use the dataframe. round() function to round off all the decimal values in the dataframe to 3 decimal places. Output : Example #2: Use round() function to round off all the columns in dataframe to different places.
Configure the following option in any cell:
pandas.options.display.float_format = '{:,.2f}'.format
You can also format the output for any float throughout the notebook with this magic command:
%precision %.2f
You can set the display.precision option with e.g.:
pd.set_option('precision', 7)
when you are done, reset it back using
pd.reset_option('precision')
as documented in https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html
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