Data analysis with Python centers on Pandas for tabular data manipulation and NumPy for numerical computing. Pandas provides DataFrames (2D labeled data structures) enabling SQL-like operations, while NumPy delivers vectorized array computations orders of magnitude faster than pure Python. Pandas 3.0 introduced Copy-on-Write by default, a dedicated str dtype, and pd.col() expressions, making data manipulation more predictable and performant. Together with NumPy's modern random Generator API (default_rng), they form the foundation of Python's data science ecosystem, handling everything from cleaning messy datasets to time series analysis and statistical aggregation.
What This Cheat Sheet Covers
This topic spans 23 focused tables and 195 indexed concepts, 151 flashcards, 7 practice tests with 241 questions. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Reading and Writing Data
Every analysis starts by getting data into a DataFrame and ends by writing results back out, and Pandas reads almost any format you'll meet. CSV and Excel cover the everyday cases, but they're untyped text, so Pandas has to guess every column's type on each read. Columnar formats like Parquet, Feather, and ORC store the schema next to the data and compress it, so a round trip hands back the dtypes you started with.
| Method | Example | Description | |
|---|---|---|---|
df = pd.read_csv('data.csv') | • Reads a comma-separated values file into a DataFrame • infers each column's type from the values, so pass dtype={'zip': 'str'} to stop digits with leading zeros parsing as int64. | ||
df = pd.read_excel('data.xlsx', sheet_name='Sheet1') | • Reads Excel files (.xls, .xlsx, .xlsm, .xlsb) and OpenDocument (.odf, .ods, .odt) • sheet_name=None returns a dict of every sheet. | ||
df.to_csv('output.csv', index=False) | • Exports a DataFrame to CSV • writes the index as an extra unnamed column unless you pass index=False. | ||
df.to_excel('output.xlsx', sheet_name='Data') | • Exports to an Excel file via the openpyxl or xlsxwriter engine• a plain call rewrites the whole file, so use pd.ExcelWriter to put several sheets in one workbook. | ||
df = pd.read_json('data.json', orient='records') | • Parses JSON into a DataFrame • orient names the layout to expect (records, columns, split, table), since JSON can hold the same table many ways. | ||
df = pd.read_sql('SELECT * FROM t', conn) | • Runs a SQL query or reads a table into a DataFrame • takes an ADBC connection, a SQLAlchemy connectable or URL string, or a sqlite3 connection • Pandas doesn't sanitize SQL, so pass values through params. | ||
df = pd.read_parquet('data.parquet') | • Reads columnar Parquet files • the schema travels with the data, so every Pandas dtype survives the round trip. | ||
df.to_parquet('data.parquet', index=False) | • Exports to Parquet, snappy-compressed by default• partition_cols=['year'] writes a directory tree of year=... folders instead of a single file. | ||
df = pd.read_feather('data.feather') | • Reads the Feather binary columnar format • preserves the schema, which suits fast handoffs between Python and R and intermediate pipeline results. | ||
df = pd.read_orc('data.orc') | • Reads ORC (Optimized Row Columnar) files through pyarrow• common in Hadoop and Hive setups, and not supported on Windows yet. | ||
tables = pd.read_html(url) | • Extracts every HTML table on a page into a list of DataFrames, never a bare one • needs lxml, or bs4 plus html5lib. |