如何打印列中的每个唯一值

问题描述 投票:1回答:2

进入:

train['brand_name'].unique()

得到结果:

array([nan, 'Razer', 'Target', ..., 'Astroglide', 'Cumberland Bay',
   'Kids Only'], dtype=object)

我需要看到每一个价值。有一些值由......表示我想知道如何展示它们。

谢谢!

python arrays pandas unique
2个回答
0
投票

如果要在IPython控制台或Jupyter中显示所有行,则应将pd.options.display.max_rows设置为不小于要打印的Pandas Series的长度(如pd.options.display.max_rows = len(train)),或者您可以将其设置为None。您可以在上下文中执行--with允许您的更改是临时的。

with pd.option_context('display.max_rows', None):
    print train['brand_name'].value_counts()
    #or, alternatively
    #print pd.Series(train['brand_name'].unique())

更多关于熊猫与显示器相关的选项:https://pandas.pydata.org/pandas-docs/stable/options.html


0
投票

这应该工作:

print('\n'.join(map(str, train['brand_name'].unique().tolist())))

说明:

  • \n代表印刷的新线条。
  • 如果您的列表中包含非文本数据,map(str, lst)会映射到字符串。
© www.soinside.com 2019 - 2024. All rights reserved.