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

Series vs. DataFrame

When you select one column from a DataFrame, you get a Series. Given the following DataFrame:

        title   author  page_count
0  The Hobbit  Tolkien         310
1        Dune  Herbert         412
2          It     King        1138

We can select the title column:

titles = df["title"]
print(titles)

Which prints the following Series:

0    The Hobbit
1          Dune
2            It
Name: title, dtype: object

Selecting Multiple Columns

When you select multiple columns from a DataFrame, you get another (smaller) DataFrame. We use double brackets here because we're actually passing a list of column names as the key for selection:

subset = df[["title", "page_count"]]
print(subset)

Which yields the following DataFrame:

        title  page_count
0  The Hobbit         310
1        Dune         412
2          It        1138

Series and DataFrame objects are not interchangeable. They support different methods and properties, so keeping track of which one you have will help you avoid errors.

Table vs. Column

Say we have a table of library books:

book_id title page_count in_stock
101 The Hobbit 310 true
102 Dune 412 false
103 It 1138 true
  • The entire table is a DataFrame.
  • The title column alone is a Series.
  • The page_count column alone is a Series.
  • If we select just the title and in_stock columns, we'll have a smaller two-column DataFrame.

Assignment

SnackStack's dashboard needs two slices of the same device table: a Series of device IDs, and an environment-panel DataFrame. The sensors report temperature in Fahrenheit, so a provided add_celsius() helper adds a "temperature_c" column for you.

Complete the get_device_views function. It accepts a DataFrame and returns a tuple of two values.