Pandas

Pandas is a way to easily analyze data in a tabular format. It is composed of Series that are put together to create DataFrames.

Import

Below is the convention for importing pandas.

import pandas as pd

Series

To create a series, simply pass any iterable to the pd.Series() command.

my_series = pd.Series(["one", "two", "three"])

Access elements of a series

Series can be accessed the same way most iterables are accessed in python.

To get a single value.

third_element = series[3]

DataFrames

DataFrames are created by either:

  1. Passing a list of iterables, where each iterable represents a row
my_dataframe = pd.DataFrame([[0, 1, 2], [3, 4, 5]])

Column names can be passed in with the columns= parameter as a list.

  1. Passing a dictionary, where each key is the column name, and the values are an interable of values to create a column.
my_dataframe = pd.DataFrame({"col_name": [0, 3], "col_name2": [1, 4]})

Table of Contents