Skip to content

Instantly share code, notes, and snippets.

View sannykhan3777's full-sized avatar
🙂

Sanny Khan sannykhan3777

🙂
View GitHub Profile
# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
# Filter for rows in the Mojave Desert states
mojave_homelessness =homelessness[homelessness["state"].isin(canu)]
# See the result
print(mojave_homelessness)
@sannykhan3777
sannykhan3777 / Subsetting data based on a categorical variable often involves using the "or" operator (|) to select rows from multiple categories. This can get tedious when you want all states in one of three different regions, for example. Instead, use the .isin()
Created July 12, 2020 13:41
Subsetting data based on a categorical variable often involves using the "or" operator (|) to select rows from multiple categories. This can get tedious when you want all states in one of three different regions, for example. Instead, use the .isin() method, which will allow you to tackle this problem by writing one condition instead of three se…
# Subset for rows in South Atlantic or Mid-Atlantic regions
south_mid_atlantic = homelessness [(homelessness["region"]=="South Atlantic") | (homelessness["region"]=="Mid-Atlantic")]
# See the result
print(south_mid_atlantic)