Is there a concise way to show all rows in pandas for just the current command?

MMelnicki

Sometimes I want to show all of the rows in a pandas DataFrame, but only for a single command or code-block.

Of course I can set the "max_rows" display option to a large number, but then I have to repeat the command afterwards in order to revert to my preferred setting. (I like 12 rows max, personally).

pd.options.display.max_rows=1000
myDF
pd.options.display.max_rows=12

That's annoying.

I read in the documentation that I can use the pd.option_context() function to accomplish this if I combine my command with a "with" statement:

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

I couldn't get that to work, (no output is returned). But I think such a solution would still be too much typing for routine incidental usage!

I wish there was some quick pythonic way to override the display options!
Does one exist? Have I overlooked something?

I like how one can alter the # of rows that the .head() function outputs by passing it an argument for the # of rows, but it still must be lower than the "display.max_rows" setting...

I know I could keep the "display.max_rows" setting really high all the time, and then tack a .head(12) function on most of the time, but I think most people would agree on how annoying that would be.

I am indeed aware that one can view all (or most of?) the values in a pandas Series by passing it to a core function such as list(). But that is tricky to do with a DF. Furthermore, it's hard to read when it's not in a tabular format.

Similar to the solution for my first question, I imagine there's probably a way to write my own function (to be placed in a startup script), but I'm not sure the best way to write it.

Ami Tavory

You could write a function that explicitly calls display

E.g., consider this function:

from IPython.display import display

def show_more(df, lines):
    foo = 1
    display(df)
    foo = 2

When I call the function (just tried it):

>> show_more(df, 1000)
... # <- Shows here the DF

then it displays the dataframe, even though the line foo = 2 is executed after. It follows that you can set the options instead of the line foo = 1 and unset it in the line foo = 2. In fact, you can just use the context manager from your question, probably.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to filter a pandas dataframe to just the rows that show change within a group?

From Dev

Is there a way to build all my Maven projects with just one command ?

From Dev

Is there a way to build all my Maven projects with just one command ?

From Dev

What is the most concise way of creating an associated array with all NULL values?

From Dev

R Markdown – a concise way to print all code snippets used in the document

From Dev

Event fires for all items not just the current item

From Dev

Concise way to run command if previous command completes successfully, when previous command is already running

From Dev

Pandas: sum all rows

From Dev

Pandas sort all rows

From Dev

Vaadin Grid: Show all rows

From Dev

How to show all rows in jqGrid?

From Dev

How to show all the rows in datagridview?

From Dev

Show all Rows of Group with Group by

From Dev

Show all table rows in <table>

From Dev

MySQL Join to show all rows

From Dev

How to show all the rows in datagridview?

From Dev

Hide all rows and show selected

From Dev

Show all rows with some special condition rows

From Dev

Show current amount of rows being read in Oracle

From Dev

Portable way to show the contents of the current directory

From Dev

Efficient way of iterating rows in pandas

From Dev

SUM() all rows after current row

From Dev

Show all user and the current user in 1 controller

From Dev

Show all the current files and directories including their statuses

From Dev

Is there a way to detect the current workspace in a command line on linux?

From Dev

Pandas Merge duplicating all rows

From Dev

More concise way to do something a maximum of X times, raising an exception if it takes X times to run the command

From Dev

How i can change current date not all just days?

From Dev

Obtain all rows, and only show one

Related Related

  1. 1

    How to filter a pandas dataframe to just the rows that show change within a group?

  2. 2

    Is there a way to build all my Maven projects with just one command ?

  3. 3

    Is there a way to build all my Maven projects with just one command ?

  4. 4

    What is the most concise way of creating an associated array with all NULL values?

  5. 5

    R Markdown – a concise way to print all code snippets used in the document

  6. 6

    Event fires for all items not just the current item

  7. 7

    Concise way to run command if previous command completes successfully, when previous command is already running

  8. 8

    Pandas: sum all rows

  9. 9

    Pandas sort all rows

  10. 10

    Vaadin Grid: Show all rows

  11. 11

    How to show all rows in jqGrid?

  12. 12

    How to show all the rows in datagridview?

  13. 13

    Show all Rows of Group with Group by

  14. 14

    Show all table rows in <table>

  15. 15

    MySQL Join to show all rows

  16. 16

    How to show all the rows in datagridview?

  17. 17

    Hide all rows and show selected

  18. 18

    Show all rows with some special condition rows

  19. 19

    Show current amount of rows being read in Oracle

  20. 20

    Portable way to show the contents of the current directory

  21. 21

    Efficient way of iterating rows in pandas

  22. 22

    SUM() all rows after current row

  23. 23

    Show all user and the current user in 1 controller

  24. 24

    Show all the current files and directories including their statuses

  25. 25

    Is there a way to detect the current workspace in a command line on linux?

  26. 26

    Pandas Merge duplicating all rows

  27. 27

    More concise way to do something a maximum of X times, raising an exception if it takes X times to run the command

  28. 28

    How i can change current date not all just days?

  29. 29

    Obtain all rows, and only show one

HotTag

Archive