Creating DataFrame objects
In this section, we will see how to create DataFrame
objects.
Getting ready
Before trying this recipe, import the numpy
and pandas
modules with the following code:
import numpy as np import pandas as pd
How to do it...
Enter the following commands in a code cell:
df1 = pd.DataFrame([['Pen', 24, 2.39], ['Eraser', 32, 1.29], ['Sharpener', 12, 10.39], ['Pencil', 42, 0.59 ]], index=[100024, 201024, 202034, 101122], columns = ['item', 'inventory', 'unit_price']) df2 = pd.DataFrame({'item': ('Pen', 'Eraser', 'Sharpener', 'Pencil'), 'inventory': (24, 32, 12, 42), 'unit_price': (2.39, 1.29, 10.39, 0.59)}, index=[100024, 201024, 202034, 101122])
This code shows how to generate two DataFrame
objects containing essentially the same data, that could represent the inventory of an office supplies store.
How it works...
In the first...