What is `pd.read_csv()`?

0165

pd.read_csv() is a function in the Pandas library used to read a comma-separated values (CSV) file into a DataFrame. It allows you to load data from a CSV file into a structured format that can be easily manipulated and analyzed in Python.

Basic Usage

Here's a simple example of how to use pd.read_csv():

import pandas as pd

# Load a CSV file into a DataFrame
df = pd.read_csv('data.csv')

# Display the first few rows of the DataFrame
print(df.head())

Common Parameters

  • filepath_or_buffer: The path to the CSV file.
  • sep: The delimiter to use (default is ,).
  • header: Row number(s) to use as the column names (default is 0).
  • index_col: Column(s) to set as the index (default is None).
  • parse_dates: Columns to parse as dates (default is False).

Example with Parameters

df = pd.read_csv('data.csv', sep=';', header=0, index_col='id', parse_dates=['date_column'])

This function is very versatile and can handle various CSV formats, making it a fundamental tool for data analysis in Python.

0 Comments

no data
Be the first to share your comment!