Limit array size on screen

Asked

Viewed 121 times

1

I am working with data from a table, but I used some commands like numpy.set_printoptions(threshold=sys.maxsize) to try to show every array without (...) omitting some items. But now I’m willing to reverse it. I used the df.head(8) to show only the first 8 items of the array, but it keeps showing all. I want to go back to the default model where the head() work.

  • and you used the set_printoptions back to a value that fits?

  • yes, I used the np.set_printoptions( threshold = 200) , but nothing happened. the array has 99 elements, it shows the first 30, ..., 69 onwards until the 98.

  • good - you just answered - with Threshold=200, you say that the Rame date will only be reformatted when you have 200 rows. Put Threshold at 8 .

  • It would be great, but I just tested with =5 and nothing has changed, there are still 99 items

1 answer

0


You are apparently confusing things - mention Numpy’s options, but say "table", and your variable has the name df, which is usually used for Pandas dataframes (which is not the same library, although it makes use of the same).

Anyway we have two things: the method head, that exists in dataframes, returns the exact number of lines - then df.head(8), generates 8 lines, and no more. If you are seeing more data than this, it may be that each element of your dataframe is other arrays. If, for example, inside your dataframe, the items inside the cells are arrays of numpy, the print options will not work.

Anyway, while how many lines are shown from a numpy.ndarray are configured by numpy.set_printoptions(threshold=...), the equivalent for pandas.Dataframe elements is

pd.options.display.max_rows = ...

both numpy and pandas boundaries work to the satisfaction - arrays and dataframes larger than the limit size are summarized, otherwise they are displayed in full.

  • It worked! Thank you! I really don’t have enough knowledge about libraries yet and sometimes I get confused. Use a lot of material from the internet so something might have unknowns. Thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.