Friday, March 28, 2025

Reading and Handling CSV Files with Pandas

 Read CSV Files with Pandas

A simple way to store big data sets is to use CSV files (comma separated files).

CSV files contains plain text and is a well know format that can be read by everyone including Pandas.

In our examples we will be using a CSV file called 'data.csv'.

Read CSV File







Common Parameters for read_csv()

File path: 'data.csv' (can be local or URL)
Delimiter: sep=',' (default is comma, but you can specify others like '\t' for TSV)
Header row: header=0 (default uses first row as column names)
Column names: names=['col1', 'col2'] (to specify your own column names)
Index column: index_col='column_name' (set a column as index)
Rows to read: nrows=100 (read only first 100 rows)

Read CSV Parameters









Understanding pd.options.display.max_rows in Pandas

Pandas has configuration options that control how DataFrames are displayed, including the maximum number of rows shown. Here's what you need to know about max_rows:

Checking Current Max Rows Setting

Max Rows







👉By default, this is typically set to 60 rows in recent Pandas versions.

Note 📢   : "On my computer, the setting is currently at 60. This means when I display a DataFrame with more than 60 rows using print(df), Pandas will automatically condense the output. Instead of showing every single row, it will display just the column headers along with the first 5 and last 5 rows from the DataFrame."

We can change the maximum rows number with the same statement.











This code:

  • Imports pandas
  • Configures pandas to display up to 9,999 rows when printing DataFrames
  • Loads your CSV file into a DataFrame
  • Prints the complete DataFrame contents (up to 9,999 rows)


No comments:

Post a Comment