Dataframe subsetting

PHOTO EMBED

Thu Nov 25 2021 10:35:12 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)

# Import numpy, you'll need this
import numpy as np

# Create medium: observations with cars_per_cap between 100 and 500
cpc = cars['cars_per_cap']
between = np.logical_and(cpc > 100, cpc < 500)
medium = cars[between]

# Print medium
print(medium)
content_copyCOPY