Locked lesson.
About this lesson
Selecting data based on conditionals - such as greater than, less than, equal to, not equal to - is an essential part of data analysis. We'll discuss that in this video.
Exercise files
Download this lesson’s related exercise files.
Conditional Selection of DataFrames.docx57.2 KB Conditional Selection of DataFrames - Solution.docx
55.5 KB
Quick reference
Conditional Selection of DataFrames
Conditional Selection allows us to select things from our DataFrame based on certain conditions.
When to use
Use this whenever you need to make a conditional selection within your DataFrame.
Instructions
We can use python conditionals to select data from a DataFrame:
>
<
>=
<=
!=
To return a list of Booleans less than 0:
my_df < 0
To return a dataframe of data less than 0
my_df[my_df < 0]
To return a specific Column less than 0:
my_df["Total"] < 0
To return rowns less than Zero in a specific column:
my_df[my_df["Total"] < 0 ]
To return rows just from a specific column less than Zero:
my_df[my_df["Total"] < 0 ]["Total"]
To return more than one column, less than zero:
my_df[my_df["Total"] < 0 ][["Mon", "Total"]]
Hints & tips
- Booleans: my_df < 0
- my_df[my_df < 0]
- my_df["Total"] < 0
- my_df[my_df["Total"] < 0 ]
- my_df[my_df["Total"] < 0 ]["Total"]
- my_df[my_df["Total"] < 0 ][["Mon", "Total"]]
Lesson notes are only available for subscribers.