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?

divine_nature
  • 89
  • 1
  • 2
  • 9

3 Answers3

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.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
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.

Ken Wei
  • 3,020
  • 1
  • 10
  • 30
  • clear and concise. – divine_nature Jul 05 '17 at 10:17
  • 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])` – Oskar Austegard Apr 15 '21 at 02:19
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')
Akshay Kandul
  • 592
  • 4
  • 10
  • what is difference between set_option and reset_option? – divine_nature Jul 05 '17 at 10:15
  • 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. – Akshay Kandul Jul 05 '17 at 10:24
  • For more information please check this links out [set_option](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html) [reset_option](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.reset_option.html) – Akshay Kandul Jul 05 '17 at 10:25
  • okay, got your point. But why to set default again? – divine_nature Jul 05 '17 at 13:03