Category Pandas

Pandas to Excel: Export a DataFrame

Pandas to Excel: Export a DataFrame

Saving a pandas DataFrame as an Excel workbook starts with DataFrame.to_excel(). It writes the table to a worksheet, where you can choose a name and whether the row index appears. I’ll show how to export a single worksheet and write…

Pandas Read Excel: Load a Workbook

Pandas Read Excel: Load a Workbook

A Python analysis can start with the values stored in an Excel worksheet. pandas.read_excel() reads worksheet values into a DataFrame, a labeled table with rows and columns. I’ll show how to read one sheet or collect several, and how to…

Pandas Get Dummies: Encode Categories

Pandas Get Dummies: Encode Categories

Turning category labels into indicator columns gives a pandas table one column for each category. pandas.get_dummies() creates those columns, using Boolean values by default or integers when you set dtype=int. I’ll show how to encode selected columns and align training…

Pandas Melt and Pivot Data

Pandas Melt and Pivot Data

A table can keep one row per record while storing each measurement in a separate column. Pandas melt turns selected measurement columns into labeled rows, and pivot reshapes those rows into columns again. This article walks through choosing columns for…

Pandas qcut: An Explanation with Examples

Pandas qcut: An Explanation with Examples

Splitting a set of numbers, such as test scores, into groups like quartiles lets you compare values by where they rank. pandas qcut does this by rank, putting a similar number of values in each group. This guide shows how…

How to Read CSV with Headers Using Pandas?

How to Read CSV with Headers Using Pandas?

Pandas reads the first CSV row as column names by default. Use pd.read_csv with header=0 when you want to state that choice explicitly, or header=None when the first row is data. The default header behavior keeps named-column selection straightforward. Read…