2

I ran a python code and got dataframe output like:

1    Department of Susta... (2)       Community Services (2)
2    Department of Commu... (2)       Community Services (2)
3    Sustainability Vict... (1)       Community Services (1)
4    Southern Grampians ... (1)       Community Services (1)
5    Productivity Commis... (1)       Community Services (1)
6         Parliament of NSW (1)       Community Services (1)
..                           ...                          ...
30      Noosa Shire Council (2)     Sport and Recreation (2)
31   State Library of Qu... (1)     Sport and Recreation (1)
32   Emergency Services ... (1)     Sport and Recreation (1)
33   Department of Susta... (1)     Sport and Recreation (1)

now i don't have rows b/w 7 to 29. How to fetch all rows?

0

3 Answers 3

8

It is only display problem, I prefer:

#temporaly display 999 rows
with pd.option_context('display.max_rows', 999):
    print (df)

Option values are restored automatically when you exit the with block.

Sign up to request clarification or add additional context in comments.

5 Comments

what if I won't apply 'with'?
I like this option because no set and reset option is necessary. Thanks.
ohh got that. Just general question, why we need to reset that and why we always have to close the file, which we have opened to proceed to next line of code?
I think you need check this article. There is explain with statement better as my explanation. Thanks.
How can the same be done in a jupyter-lab notebook with a scrolling table?
4

As of 0.20.2, pandas displays only 60 rows from your data by default. You can change this with

pd.set_option('display.max_rows',n)

where n is the number of rows you want it to display.

2 Comments

clear and concise.
this doesn't quite work as expected - it works fine if the row count is less than or equal to n, but if the row count is greater than n, python will revert back to displaying the first 5 and last 5. To make this work for any dataframe df you can use pd.set_option('display.max_rows', df.shape[0])
3

You can create a function like this one

def print_full(x):
    pd.set_option('display.max_rows', len(x))
    print(x)
    pd.reset_option('display.max_rows')

4 Comments

what is difference between set_option and reset_option?
set_option sets the value of the specified option and reset_option Resets one or more options to their default value. In our example we have changed max_rows default value from 15 to length of dataframe. So reset_option just moves back to default value.
For more information please check this links out set_option reset_option
okay, got your point. But why to set default again?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.