Understanding the differences between base Python and pandas data selection
For the most part, once you have learned a bit of pandas notation for slicing and indexing, pandas objects work nearly transparently with core Python. Since the indexing of some different object types looks similar, here, we'll touch on some of the differences so that you can avoid surprises in the future.
Lists versus Series access
Python lists look superficially like Series. When you're using bracket notation to index a Series, it works much the same way as indexing a list. Here, we make a simple list using the range()
function, then print out 11 values within the list:
my_list = list(range(100)) print(my_list[12:33])
This will produce the following output:
[12  13,  14,  15,  16,  17,  18,  19,  20,  21,  22]
Now, let's attempt the same thing, but using .iloc[]
:
print(my_list...