We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

DataFrames

While a Series represents a single column of data, a DataFrame is basically a table that can contain an arbitrary number of Series (columns).

It's essentially Pandas' version of an Excel spreadsheet, CSV file, or SQL table.

Say we have a collection of a few columns that represent player data from an RPG:

data = {
    "player": ["Geralt", "Ciri", "Triss"],
    "gold_earned": [150, 300, 75],
    "online": [True, False, True],
}

df = pd.DataFrame(data)
print(df)

Prints:

   player  gold_earned  online
0  Geralt          150    True
1    Ciri          300   False
2   Triss           75    True
  • The index labels are on the left: 0, 1, 2
  • The column labels are at the top: player, gold_earned, online
  • The values are in the middle: the actual data for each player

DataFrames are everywhere in data manipulation; we'll be using these a lot.

We'll often use the variable name df as a concise way of representing a DataFrame in examples.

Assignment

Complete the create_device_dataframe function. It accepts a dictionary with three lists and returns a Pandas DataFrame with an added human-readable status column.

Try printing the data before and after putting it in the DataFrame to see the difference in formatting!