gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:45:41 25 4
gpt4 key购买 nike

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

问题是我只在输出中看到截断的结果。我正在 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

目前我正在使用这个,但是相当麻烦:

print(df.col1.value_counts()[:50])
print(df.col1.value_counts()[50:100])
print(df.col1.value_counts()[100:150])
# etc.

此外,我已阅读 this相关的堆栈溢出问题,但没有发现它有帮助。

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

最佳答案

如果要打印所有行:

pd.options.display.max_rows = 1000
print(vals)

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

with pd.option_context("display.max_rows", 1000):
print(vals)

相关文档here .

关于pandas - 使用 pd.Series.value_counts() 时如何阻止 Jupyter 输出截断的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43909817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com