How it works...
The col = df['item'] line of code selects the column index from the DataFrame and returns in the col variable a Series object containing the specified column. Analogously, the cols = df[['item', 'inventory']] line selects two columns. Notice that, in this case, the object returned is a DataFrame.
In the next example, we use rows = df[2:4] to select a range of rows from the DataFrame. Notice that this uses the standard convention for ranges in Python and rows two and three are returned.
The next two examples show the use of the loc indexing method.
With the row_data = df.loc[201024] line we select one row of data. The returned object is a Series, where the indexes are the column names of the DataFrame.
Then, the df1 = df.loc[201024:,['item','unit_price']] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access