Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Jupyter outputting truncated results when using pd.Series.value_counts()?

I have a DataFrame and I want to display the frequencies for certain values in a certain Series using pd.Series.value_counts().

The problem is that I only see truncated results in the output. I'm coding in Jupyter Notebook.

I have tried unsuccessfully a couple of methods:

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

Currently this is what I'm using, but it's quite cumbersome:

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

Also, I have read this related Stack Overflow question, but haven't found it helpful.

So how to stop outputting truncated results?

like image 538
Alex Avatar asked Dec 08 '22 18:12

Alex


1 Answers

If you want to print all rows:

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

If you want to print all rows only once:

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

Relevant documentation here.

like image 79
IanS Avatar answered Jun 17 '23 18:06

IanS