Reputation: 52253
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.)
Upvotes: 10
Views: 5743
Reputation: 11
If the purpose of printing is to see the data from the console, You could turn it into a python list.
print(list(df.columns))
This should show the data in full without any abbreviate. However this may not be the solution to tell pandas to not abbreviate an output.
Upvotes: 1
Reputation: 139162
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.
Upvotes: 10
Reputation: 351
Here is a concise way to get what you want:
for i in df.columns:
print(i,end=", ")
the value of the end
parameter can be anything you like, including the default \n
.
Upvotes: 0