I have a Pandas DataFrame that I'm printing in the Spyder console. I want an option that expands the # of columns printed without wrapping onto new lines. I don't mind if I have to manually set the print width.
I followed this link: How do I expand the output display to see more columns of a Pandas DataFrame?
to try and get more columns. However I can't get any of the proposed solutions to work.
Basically, from the Pandas documentation it seems that there is an issue with autodetecting width in certain consoles. My impression is that the Spyder Console may be impacted. This is specifically for display.width
Manually setting display.width does not seem to work. Changing display.max_columns sometimes works but sometimes doesn't and sometimes wraps lines (which I don't want).
It seems that both display.width and display.max_columns are needed ...
Here's some code and notes. I ran each of the settings options independently or in pairs of 2, after clearing the console and re-running the setup code. The final test is just to type df in the console.
import numpy as np
import pandas as pd
rng = np.random.default_rng()
n_columns = 20
names = []
for i in range(n_columns):
names.append('Testing%d' % (i,))
df = pd.DataFrame(rng.integers(0, 100, size=(100, n_columns)), columns=names)
#Explicit wrap
pd.set_option('display.max_columns',10)
#Doesn't work - why not????
pd.set_option('display.width',200)
#Works ...
pd.set_option('display.width',200)
pd.set_option('display.max_columns',10)
#Doesn't work. I guess odds aren't allowed ...?
pd.set_option('display.width',200)
pd.set_option('display.max_columns',11)
#Works ...
pd.set_option('display.width',200)
pd.set_option('display.max_columns',12)
#[soft] Wrap around - presumably 200 is too high
pd.set_option('display.width',200)
pd.set_option('display.max_columns',14)
#Doesn't respect width, explicit wrap
pd.set_option('display.width',200)
pd.set_option('display.max_columns',None)
It seems like the only solution that sort of works is to set the display width to be something large and then to adjust the # of columns on a case by case basis. It would be nice to have a 1 liner that works, or even better, to have a solution that just always prints to the display width.
I'm using Python 3.8, Spyder 4.2.0 and Pandas 1.2.0