Pandas Concepts: Reference and Examples

Last updated:
Table of Contents

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

Index

A Index is just a Numpy array.

An Index is used to locate elements in a Series or rows in a DataFrame.

import pandas as pd

i = pd.Index([0,1,2,3])
# Int64Index([0, 1, 2, 3], dtype='int64')

An Index may contain non-numeric elements

import pandas as pd

string_i = pd.Index(['a','b','c','d'])
string_i
#Index(['a', 'b', 'c', 'd'], dtype='object')

Series

A Series is an array plus an Index.

import pandas as pd

i = pd.Index([0,1,2,3])
# Int64Index([0, 1, 2, 3], dtype='int64')

s = pd.Series([10,20,30,40],index=i)
# 0    10
# 1    20
# 2    30
# 3    40
# dtype: int64

Access elements in a Series using the Index

TODO

An Index is created by default when you create a Series

TODO

Dataframe

A dataframe is a list of Series objects, where all Series have the same index.

Index vs Series

The Index is part of a Series.

Series = Index + Data array

Series vs Dataframe

A dataframe is a list of Series objects, where all Series have the same index.

You can turn a Series into a DataFrame (with a single column) by calling .toframe() on the Series object.

Dataframes and Indexes

TODO

Dialogue & Discussion