在 Jupyter Python Notebook 中显示所有数据框列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47022070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:58:38  来源:igfitidea点击:

Display all dataframe columns in a Jupyter Python Notebook

pythonpython-3.xdataframejupyter-notebook

提问by Michail N

I want to show all columns in a dataframe in a Jupyter Notebook. Jupyter shows some of the columns and adds dots to the last columns like in the following picture:

我想在 Jupyter Notebook 的数据框中显示所有列。Jupyter 显示一些列并在最后一列添加点,如下图所示:

Juputer Screenshot

木星截图

How can I display all columns?

如何显示所有列?

回答by Isma

Try the display max_columns setting as follows:

尝试显示 max_columns 设置如下:

import pandas as pd
from IPython.display import display

df = pd.read_csv("some_data.csv")
pd.options.display.max_columns = None
display(df)

Or

或者

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

Edit: Pandas 0.11.0 backwards

编辑:熊猫 0.11.0 向后

This is deprecated but in versions of Pandas older than 0.11.0 the max_columnssetting is specified as follows:

这已被弃用,但在 0.11.0 之前的 Pandas 版本中,max_columns设置指定如下:

pd.set_printoptions(max_columns=500)

回答by Hannah

I know this question is a little old but the following worked for me in a Jupyter Notebook running pandas 0.22.0 and Python 3:

我知道这个问题有点旧,但以下内容在运行 Pandas 0.22.0 和 Python 3 的 Jupyter Notebook 中对我有用:

import pandas as pd
pd.set_option('display.max_columns', <number of columns>)

You can do the same for the rows too:

您也可以对行执行相同的操作:

pd.set_option('display.max_rows', <number of rows>)

This saves importing IPython, and there are more options in the pandas.set_option documentation: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.set_option.html

这节省了导入 IPython,并且在 pandas.set_option 文档中有更多选项:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.set_option.html

回答by rsc05

Python 3.x for large (but not too large) DataFrames

用于大型(但不是太大)DataFrame 的 Python 3.x

Maybe because I have an older version of pandas but on Jupyter notebook this work for me

也许是因为我有一个旧版本的熊猫,但在 Jupyter notebook 上这对我有用

import pandas as pd
from IPython.core.display import HTML

df=pd.read_pickle('Data1')
display(HTML(df.to_html()))

回答by Zephaniah Grunschlag

I recommend setting the display options inside a context manager so that it only affects a single output. If you also want to print a "pretty" html-version, I would define a function and display the dataframe dfusing force_show_all(df):

我建议在上下文管理器中设置显示选项,以便它只影响单个输出。如果您还想打印“漂亮”的 html 版本,我将定义一个函数并df使用force_show_all(df)以下方法显示数据框:

from IPython.core.display import display, HTML

def force_show_all(df):
    with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.width', None):
        display(HTML(df.to_html()))

As others have mentioned, be cautious to only call this on a reasonably-sized dataframe.

正如其他人所提到的,请谨慎仅在合理大小的数据帧上调用它。

回答by Shaina Raza

you can use pandas.set_option(), for column, you can specify any of these options

您可以使用pandas.set_option(),对于列,您可以指定这些选项中的任何一个

pd.set_option("display.max_rows", 200)
pd.set_option("display.max_columns", 100)
pd.set_option("display.max_colwidth", 200)

For full print column, you can use like this

对于完整的打印列,您可以像这样使用

import pandas as pd
pd.set_option('display.max_colwidth', -1)
print(words.head())

enter image description here

在此处输入图片说明