Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Pandas - how can I avoid ellipsis when using 'describe'

I am opening a file with many features in iPython notebook (~145k observations, ~ 2000 features). When using df.describe, the output uses ellipsis in summarizing the features. How can I output the description of all the rows to a file?

[In]
url = "some large file"
df = pd.read_csv(url)
df.describe()

[Out]
       Col 1    Col 2    Col 3    Col 4   ...  Col 1998   Col 1999   Col 2000
mean   Blah     Blah     Blah     Blah    ...  Blah       Blah       Blah
std
min 
etc

I thought I could avoid the ellipsis by writing the output to a file:

[In]
url1 = "Some output file"
f = open(url1, 'w')
f.write(str(df.describe()))
f.close()

But the file looks the same as the output.

like image 463
GPB Avatar asked Dec 01 '22 14:12

GPB


1 Answers

pd.options.display.max_columns = 2000

If you don't want to make the change permanently for the notebook, (e.g., to avoid excessive output in other cells), you can also use pd.option_context:

with pd.option_context('display.max_columns', 2000):
     print(df.describe())
like image 147
Randy Avatar answered Dec 06 '22 09:12

Randy