filtering
The DataFrame `trips` is preloaded. Write sf_trips(df) that returns trips where city == 'SF', keeping only trip_id, driver, and fare columns (in that order).
preloaded fixtures
import pandas as pd
import numpy as np
trips = pd.DataFrame({
"trip_id": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"driver": ["alex", "alex", "sam", "sam", "alex", "jordan", "jordan", "sam", "alex", "jordan"],
"city": ["SF", "SF", "NYC", "NYC", "SF", "LA", "LA", "NYC", "SF", "LA"],
"fare": [12.5, 8.0, 20.0, 15.0, 9.5, 18.0, 22.0, 11.0, 14.0, 16.5],
"surge": [1.0, 1.0, 1.5, 1.2, 1.0, 2.0, 1.5, 1.0, 1.3, 1.8],
"distance": [3.2, 2.1, 5.5, 4.0, 2.8, 6.0, 7.2, 3.5, 3.8, 5.0],
})
Guest mode · solve history stays on this device; code isn’t saved. Sign in to save future work
solution.py
loading editor…
Run your code to see its output, or check your solution to grade it.