How to remove ellipsis from a row in a Python Pandas series or data frame, shown when long lines/wide columns are truncated?

℡╲_俬逩灬. 提交于 2019-11-27 02:24:34

问题


When I create the following Pandas Series:

    pandas.Series(['a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']

I get this as a result:

    0                                                    a
    1    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
    2    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
    3                                     aaaaaaaaaaaaaaaa
    4    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

How can I instead get a Series without the ellipsis that looks like this:

    0                                                                         a
    1    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    2         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    3                                                          aaaaaaaaaaaaaaaa
    4        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

回答1:


pandas is truncating the output, you can change this:

In [4]:

data = pd.Series(['a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'])

pd.set_option('display.max_colwidth',1000)

data

Out[4]:

0                                                                         a
1    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3                                                          aaaaaaaaaaaaaaaa
4        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
dtype: object

also see related: Output data from all columns in a dataframe in pandas and Output data from all columns in a dataframe in pandas

By the way if you are using IPython then if you do a docstring lookup (by pressing tab) then you will see the current values and the default values (the default is 50 characters).

For Pandas versions older than 0.10 use

pd.set_printoptions(max_colwidth, 1000)

See related: Python pandas, how to widen output display to see more columns?



来源:https://stackoverflow.com/questions/21028819/how-to-remove-ellipsis-from-a-row-in-a-python-pandas-series-or-data-frame-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!