Curriculum
Course: Pandas
Login
Text lesson

Key/Value Objects as Series

You can also create a Series using a key/value object, such as a dictionary.

Example

You can create a simple Pandas Series from a dictionary like this:

import pandas as pd

calories = {“day1”420“day2”380“day3”390}

myvar = pd.Series(calories)

print(myvar)

To select specific items from the dictionary, use the index argument and specify the items you want to include in the Series.

Example

Create a Series using data only from “day1” and “day2”:

import pandas as pd

calories = {“day1”420“day2”380“day3”390}

myvar = pd.Series(calories, index = [“day1”“day2”])

print(myvar)

DataFrames

In Pandas, datasets are typically represented as multi-dimensional tables called DataFrames. While a Series is similar to a column, a DataFrame represents the entire table.

Example

You can create a DataFrame by combining two Series:

import pandas as pd

data = {
  “calories”: [420380390],
  “duration”[504045]
}

myvar = pd.DataFrame(data)

print(myvar)