Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing pandas Index in full

Tags:

python

pandas

In order to print pandas DataFrame or Series in full, we can use pd.set_option('display.max_rows', None). But this doesn't seem to work on the Index datatype:

import pandas as pd
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None) # just in case
d = {i: ['a'] for i in range(1000)}
df = pd.DataFrame(d)
print(df.columns)

will print

Int64Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
        ...
        990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
       dtype='int64', length=1000)

Is there a way to make the index print in full?

In general, is there a way to tell pandas to never abbreviate any output?

(python 3.5, pandas 0.17.1, but it shouldn't matter.)

like image 201
max Avatar asked Jan 25 '16 03:01

max


1 Answers

It's the option max_seq_items that is used for this:

In [21]: pd.options.display.max_seq_items
Out[21]: 100

In [22]: pd.options.display.max_seq_items = 4

In [23]: pd.Index(range(1000))
Out[23]:
Int64Index([  0,   1,
            ...
            998, 999], dtype='int64', length=1000)

And setting it to None will display the full index.

like image 135
joris Avatar answered Sep 30 '22 05:09

joris