Tutorial by Examples

This will be our example data frame: df = pd.DataFrame({"color": ['red', 'blue', 'red', 'blue']}, index=[True, False, True, False]) color True red False blue True red False blue Accessing with .loc df.loc[True] color True red True red ...
This will be our example data frame: color name size 0 red rose big 1 blue violet big 2 red tulip small 3 blue harebell small Using the magic __getitem__ or [] accessor. Giving it a list of True and False of the same length as the dataframe will give you: ...
This will be our example data frame: color name size 0 red rose big 1 blue violet small 2 red tulip small 3 blue harebell small Accessing a single column from a data frame, we can use a simple comparison == to compare every element in the column to the given...
This will be our example data frame: color size name rose red big violet blue small tulip red small harebell blue small We can create a mask based on the index values, just like on a column value. rose_mask = df.index == 'rose' df[rose_mask...

Page 1 of 1