Pandas by default limits the number of printing character to 80. This is good and basically suits most of the use-cases. However, sometimes, you have either very long names for your dataframe columns, or you have lots of columns, which results on having your dataframe splitted in several lines, while half of our big screen it’s not used at all. That’s quite a lot of real estate thrown away for not good reason and it makes a tad more complicated to read it.
You can live with it, and all will be fine, or you can change it!
I always knew that there was an easy way to change this and avoid to have the line being splitted on the new line. Today I’ve researched and found it, and I am sharing here to remember it!
Just import the module and bump the width to 180 (default is 80)
import pandas as pd pd.options.display.width = 180
The result is pretty cool.
Consider this dataframe:
import pandas as pd df = pd.DataFrame({"very_long_column_name_for_example_purposes1" : [1,2,3], "very_long_column_name_for_example_purposes2": [4,5,6], "very_long_column_name_for_example_purposes3": [1,2,3]})
You can go from this:
To this (click on it to see it in full size):
August 15, 2015 at 11:04 pm
WOW! This has been bugging me forever and I could not find a solution. You’ve made my day with this.
August 16, 2015 at 9:43 am
Glad it helped!
August 9, 2016 at 11:23 am
Thanks!