Pandas DataFrame: Show All Columns/Rows

Pandas DataFrame: Show All Columns/Rows

On this story, I’ll clarify the right way to view all objects. columns and rows of a Pandas DataFrame. I can even clarify the right way to show all values ​​in a listing in a DataFrame and the way to decide on the precision of numbers in a DataFrame. And you are able to do all of it with the identical software.

5 Steps to View All Columns and Rows in Pandas

  1. Go to choices configuration in Pandas.
  2. Show all columns with: “show.max_columns.”
  3. Set the utmost column width with: “max_columns.”
  4. Substitute the variety of rows with “max_rows” and “min_rows”.
  5. Set the order of the objects with: “max_seq_items.”

I’ll use the dataset of the highest 250 IMDB motion pictures downloaded from: Data World. The database has 250 rows and 37 columns.

Downside: Pandas Cuts Info

Typically you may learn with a DataFrame many rows or columnshowever once you view it in Jupyter, the rows and columns are hidden (highlighted in pink containers):

motion pictures = pd.read_csv("information/IMDB_Top250movies2_OMDB_Detailed.csv")
motion pictures
Some rows and columns are hidden (red boxes).
Some rows and columns are hidden (pink containers). | Screenshot: Andryw Marques

They’re normally hidden in order to not present an excessive amount of data. However typically it’s possible you’ll wish to see all columns and rows. So how will we print all of them?

To do that we have to mess around with the choices parameters. pandas Let’s examine.

Extra on pandas: Sorting Data Frames in Pandas: A Hands-On Guide

Present All Columns and Rows in Pandas

Now I’ll go over the completely different instructions you need to use to alter the variety of columns and rows you may see in Pandas, for instance:

  • show.max_columns
  • max_colwidth
  • max_rows and min_rows
  • max_seq_items 

choose Alternative

there are pandas options configuration Menu that means that you can change the show settings of your DataFrame (and extra).

All it’s a must to do is select your choice with a string title and get/set/reset its values. These capabilities settle for an everyday expression sample, so in case you move a substring, it can work so long as a number of choices do not match.

view columns

This show.max_columns choice controls the variety of columns to print. takes one int or Nonethe second is used to print all columns):

pd.set_option('show.max_columns', None)
motion pictures.head()
Columns are no longer hidden.  Jupyter creates a scrollbar.
Columns are now not hidden. Jupyter creates a scrollbar. | Screenshot: Andryw Marques

You may as well use string max_columns instead show.max_columns. Word that it accepts an everyday expression:

pd.set_option('max_columns', None)

To move a quantity as a substitute of “None”, enter:

pd.set_option('max_columns', 2)
motion pictures.head()
Only 2 columns are shown.
Solely 2 columns are proven. | Screenshot: Andryw Marques

To revert to the default worth, it’s essential reset the choice:

motion pictures.head()
Some columns are hidden again.
Some columns are hidden once more. | Screenshot: Andryw Marques

Extra on pandas: Clipboard to DataFrame with Pandas: A Quick Guide

arrange column width

You possibly can change the column width with the choice. max_colwidth. For instance, the “plot” column has a number of characters, and the picture was initially lower:

Some text of the drawing column is hidden.
Some textual content of the drawing column is hidden. | Screenshot: Andryw Marques

You possibly can enhance the width. int. Or put it on max move None:

pd.set_option(“max_colwidth”, None)
motion pictures[[“Title”, “Plot”]].head()
Showing all the text of the drawing column.
Exhibiting all of the textual content of the drawing column. | Screenshot: Andryw Marques

Altering the Variety of Rows

To vary the variety of rows it’s essential change max_rows selection.

pd.set_option("max_columns", 2) #Exhibiting solely two columns
pd.set_option("max_rows", None)
motion pictures
All rows are shown.  Jupyter collapses the cell and creates a scrollbar.
All rows are proven. Jupyter collapses the cell and creates a scrollbar. | Screenshot: Andryw Marques

There are two settings concerning rows: max_rows and min_rows. When the variety of rows is multiple max_rowsThe DataFrame is truncated and reveals: min_rows rows.

For instance, let’s reprint DataFrame motion pictures with default values. max_rows and min_rows:

print("Default max_rows: {} and min_rows: {}".format(
pd.get_option("max_rows"), pd.get_option("min_rows")))
motion pictures
Printing DatFrame movies with max_rows and min_rows.
Printing DatFrame motion pictures with max_rows and min_rows. | Picture: Andryw Marques

Because the variety of rows within the dataframe is 250 max_rows A price of 60 signifies the primary and final 5 strains; min_rows The worth we set as 10.

if we alter min_rows by two, it shows solely the primary and final strains:

pd.set_option(“min_rows”, 2)
motion pictures
Only 2 rows are shown, first and last.
Solely 2 rows are proven, first and final. | Screenshot: Andryw Marques

If we use head command with a worth under max_rows worth (60), all rows are proven. For instance, utilizing head With a worth of 20:

motion pictures.head(20)
All 20 rows are shown because this value is less than max_rows (60).
All 20 rows are proven as a result of this worth is lower than max_rows (60). | Screenshot: Andryw Marques

Set the Order of Objects

The order of things (lists) can even be truncated in the event that they comprise too many characters:

#Create "my_list" column and put a listing of 100 values in every row
motion pictures[‘my_list’] = [[1]*100] * 250 
motion pictures.head()
Truncated array of items (lists.)
Truncated array of things (lists.) | Screenshot: Andryw Marques

Possibility to alter this conduct max_seq_items. However we even have to alter max_colwidth. if we alter max_colwidth, The lists can be shortened:

pd.set_option(“max_colwidth”, None)
motion pictures.head()
The “my_list” column has been expanded, however the lists have been shortened. | Screenshot: Andryw Marques

So, you’ll need to alter max_seq_item.

pd.set_option(“max_seq_item”, None)
motion pictures.head()
All values ​​of the lists are displayed.
All values ​​of the lists are displayed. | Screenshot: Andryw Marques

All values ​​of the lists are displayed. | Screenshot: Andryw Marques

Extra on pandas: Pandas Pivot Table Guide

Precision of numbers

One other helpful choice is to set the floating level precision or the variety of digits after the decimal utilizing the precision choice.

#including extra decimal locations to imdbRating column
motion pictures[‘imdbRating’] = motion pictures[‘imdbRating’] + 0.11111
motion pictures[[‘imdbRating’]].head()
Numbers with 5 decimal places.
Numbers with 5 decimal locations. | Screenshot: Andryw Marques
Numbers with 2 decimal places.
Numbers with 2 decimal locations. | Screenshot: Andryw Marques
pd.set_option(‘precision’, 2)
motion pictures[[‘imdbRating’]].head()

#Pandas #DataFrame #Present #ColumnsRows

Leave a Reply

Your email address will not be published. Required fields are marked *