Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

python - ipython notebook pandas max allowable columns

I have a simple csv file with ten columns!

When I set the following option in the notebook and print my csv file (which is in a pandas dataframe) it doesn't print all the columns from left to right, it prints the first two, the next two underneath and so on.

I used this option, why isn't it working?

pd.option_context("display.max_rows",1,"display.max_columns",100)

Even this doesn't seem to work:

pandas.set_option('display.max_columns', None)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I assume you want to display your data in the notebook than the following options work fine for me (IPython 2.3):

import pandas as pd
from IPython.display import display
data = pd.read_csv('yourdata.txt')

Either directly set the option

pd.options.display.max_columns = None
display(data)

Or, use the set_option method you showed actually works fine as well

pd.set_option('display.max_columns', None)
display(data)

If you don't want to set this options for the whole script use the context manager

with pd.option_context('display.max_columns', None):
    display(data)

If this doesn't help, you might give a minimal example to reproduce your issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...