使用 pd.Series.value_counts() 时如何停止 Jupyter 输出截断的结果?

Ale*_*lex 4 pandas jupyter-notebook

我有一个DataFrame,我想在某个Seriesusing 中显示某些值的频率pd.Series.value_counts()

问题是我只在输出中看到截断的结果。我在 Jupyter Notebook 中编码。

我尝试了几种方法都没有成功:

df = pd.DataFrame(...) # assume df is a DataFrame with many columns and rows

# 1st method
df.col1.value_counts()

# 2nd method
print(df.col1.value_counts())

# 3rd method
vals = df.col1.value_counts()
vals  # neither print(vals) doesn't work

# All output something like this
value1         100000
value2         10000
...
value1000      1
Run Code Online (Sandbox Code Playgroud)

目前这是我正在使用的,但它非常麻烦:

print(df.col1.value_counts()[:50])
print(df.col1.value_counts()[50:100])
print(df.col1.value_counts()[100:150])
# etc.
Run Code Online (Sandbox Code Playgroud)

另外,我已经阅读了这个相关的堆栈溢出问题,但没有发现它有帮助。

那么如何停止输出截断的结果呢?

Ian*_*anS 10

如果要打印所有行:

pd.options.display.max_rows = 1000
print(vals)
Run Code Online (Sandbox Code Playgroud)

如果只想打印所有行一次:

with pd.option_context("display.max_rows", 1000):
    print(vals)
Run Code Online (Sandbox Code Playgroud)

相关文档在这里