Filter observations from a DataFrame based on boolean arrays: Part 1

PHOTO EMBED

Thu Nov 25 2021 09:43:49 GMT+0000 (UTC)

Saved by @Sourabh #numpy #booleans_in_numpy

# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)

# Extract drives_right column as Series: dr
cars['drives_right']
dr = cars['drives_right']

# Use dr to subset cars: sel
sel = cars[dr]

# Print sel
print(sel)
content_copyCOPY