Accessing Data in a DataFrame
00:00 Since a DataFrame is a collection of Series, everything you learned in the previous lesson also applies to DataFrames. But DataFrames are two-dimensional, so indexing them is a little different.
It has a
'revenue' column and the values in the column are stored in a
Series with the city names as the index. For column names that are strings, you can treat them like attributes of the
DataFrame and get each
Series using dot notation.
Keep in mind that dot notation will not work if the column name is a
DataFrame attribute or method name. For example, if you had a column named
'shape', you could access it with the indexing operator but not with dot notation.
.shape is an attribute of the
DataFrame and will always return the dimensions of the
DataFrame. In general, dot notation should only be used in interactive sessions, such as a Jupyter Notebook.
Another trick that works on Python lists is negative indexing. For example, the second to last item in a list could be found at index
-2. The same goes for the second to last row of a
DataFrame using the
.iloc attribute. Try it out on the
In the previous lesson, the
.iloc attributes used only a single value, but DataFrames have a second dimension and the
.iloc attributes have been extended to take advantage of it.
Become a Member to join the conversation.