Pandas
I/O Operations
Read and write CSV, Excel, Parquet, and SQL.
By EZ4Code Team
iocsvparquet
Code
import pandas as pd
from sqlalchemy import create_engine
df = pd.DataFrame({"name": ["A", "B"], "value": [1, 2]})
# CSV
df.to_csv("data.csv", index=False)
loaded = pd.read_csv("data.csv", usecols=["name"])
# Excel
df.to_excel("data.xlsx", sheet_name="Sheet1", index=False)
xls = pd.read_excel("data.xlsx", sheet_name="Sheet1")
# Parquet (columnar, compressed)
df.to_parquet("data.parquet")
pq = pd.read_parquet("data.parquet")
# SQL
engine = create_engine("sqlite:///app.db")
df.to_sql("items", engine, if_exists="replace", index=False)
from_db = pd.read_sql("SELECT * FROM items", engine)Explanation
Pandas provides read_* and to_* helpers for many formats with sensible defaults. Parquet is columnar and compressed, ideal for large datasets, while CSV remains the lingua franca. to_sql and read_sql bridge DataFrames and databases through a SQLAlchemy engine.
More Pandas Snippets
DataFrame Creation
Build DataFrames from dicts, lists, and files.
Indexing and Selecting
Select rows and columns with loc, iloc, and masks.
GroupBy Operations
Split, aggregate, and transform with groupby.
Merge and Join
Combine frames with merge and concat.
Pivot Tables
Reshape data with pivot, melt, and pivot_table.
Time Series
Resample, shift, and roll windows over time data.