A common method for storing large datasets is using CSV (comma-separated values) files. These files contain plain text and are widely recognized, making them easily readable by tools like Pandas. In our examples, we will use a CSV file named ‘data.csv’.
Load the CSV file into a DataFrame:
import pandas as pd df = pd.read_csv(‘data.csv’) print(df.to_string()) |
Tip: Use to_string() to display the entire DataFrame. |
If you have a large DataFrame with numerous rows, Pandas will display only the first 5 and the last 5 rows.
Print the DataFrame without using the to_string()
method:
import pandas as pd df = pd.read_csv(‘data.csv’) print(df) |
The number of rows displayed is controlled by Pandas’ option settings. You can check your system’s maximum row limit using the pd.options.display.max_rows
statement.
Check the maximum number of rows that can be returned:
import pandas as pd print(pd.options.display.max_rows) |
On my system, the maximum row limit is 60, meaning that if the DataFrame contains more than 60 rows, the print(df)
statement will only display the headers along with the first and last 5 rows.
You can adjust this maximum row limit using the same statement.
Increase the maximum number of rows to display the full DataFrame:
import pandas as pd pd.options.display.max_rows = 9999 df = pd.read_csv(‘data.csv’) print(df) |