In the real world, data is huge so is the dataset. While importing a dataset and converting it into DataFrame, the default printing method does not print the entire DataFrame. It compresses the rows and columns. In this article, we are going to learn how to pretty-print the entire DataFrame?
Pandas have the set_options() method which allows us to set different properties according to our requirements and pretty print the entire Dataframe. Below are some pretty print options.
- display.max_columns: It defines the total number of columns to be printed. If None is passed as an argument, all columns would be printed.
- display.max_rows: It defines the total number of rows that need to be printed. If None is passed as an argument all rows would be printed.
- display.width: It is also an important option that defines the width of the display. If set to None, pandas will correctly auto-detect the width.
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
                                                                     
                            
Example:
Output:
Created DataFrame: Name Age Gender ... Salary Location Marriage Status 0 Hari 25 Male ... 200000 Amritsar 0 1 Mohan 36 Male ... 50000 Indore 1 2 Neeti 26 Female ... 500000 Mumbai 1 3 Shaily 21 Female ... 0 Bhopal 0 4 Ram 30 Male ... 100000 Gurugram 1 5 Umesh 33 Male ... 75000 Pune 0 6 Shirish 35 Male ... 10000000 Banglore 0 7 Rashmi 40 Female ... 50000 Ranchi 1 8 Pradeep 39 Male ... 50000 Surat 1 9 Neelam 45 Female ... 200000 Chennai 1 10 Jitendra 42 Male ... 200000 Shimla 0 11 Manoj 39 Male ... 150000 Kolkata 1 12 Rishi 48 Male ... 15000 Raipur 0 [13 rows x 8 columns]Hence, by setting different options using the set_options() method, we are now able to see all the columns of our DataFrame including 'Profession' and 'Title'.
need an explanation for this answer? contact us directly to get an explanation for this answer