Exercise: Pandas from dictionaries

In [1]:
import pandas as pd

While numpy arrays have an implicitly defined integer index used to access the values, the pandas objects have an explicitly defined index associated with the values, a feature shared with the python dictionary construct. To begin our pandas exercises, start by converting dictionaries to pandas objects.

Tasks:

  1. Convert d0 to a corresponding pandas object pd0.
In [2]:
d0 = {2:'a', 1:'b', 3:'c'}
  1. Sort indices of pd0.

(Note: Newer versions of pandas do not sort dictionary keys.)

  1. Convert d1, d2 (together) to a pandas object dd.
In [3]:
d1 = {'a': 1, 'b': 2}
d2 = {'b': 3, 'c': 4}
  1. Give examples of indexing and slicing on dd.

In pandas, indexing refers to accessing columns by their names, in a syntax reminiscent of dictionary access by keys, while slicing refers to row access like in numpy.

  1. Give examples of implicit and explicit indexing on dd.
  1. Forward fill and backfill missing values using various axis.