Home Explore Blog CI



nushell

5th chunk of `cookbook/polars_v_pandas_v_nushell.md`
b7a4abe48b367b37f5f7616ae0d2603943a56c1f8352d5f00000000100000d39
# => │ 4 │ id2181028 │         2 │ 2016-03-26    │ 2016-03-26    │             1 │        -73.97 │         40.79 │        -73.97 │         40.78 │ N            │         7.25 │
# => │   │           │           │ 13:30:55      │ 13:38:10      │               │               │               │               │               │              │              │
# => ╰───┴───────────┴───────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴──────────────┴──────────────╯
```

## 5. Opening the file and filtering out all rows with a trip duration shorther than 500 seconds

```nu
$df | polars filter-with ((polars col trip_duration) >= 500) | polars first 5 | polars collect
# => ╭───┬───────────┬───────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬──────────────┬──────────────╮
# => │ # │    id     │ vendor_id │ pickup_dateti │ dropoff_datet │ passenger_cou │ pickup_longit │ pickup_latitu │ dropoff_longi │ dropoff_latit │ store_and_fw │ trip_duratio │
# => │   │           │           │ me            │ ime           │ nt            │ ude           │ de            │ tude          │ ude           │ d_flag       │ n            │
# => ├───┼───────────┼───────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼──────────────┼──────────────┤
# => │ 0 │ id2377394 │         1 │ 2016-06-12    │ 2016-06-12    │             1 │        -73.98 │         40.74 │        -74.00 │         40.73 │ N            │          663 │
# => │   │           │           │ 00:43:35      │ 00:54:38      │               │               │               │               │               │              │              │
# => │ 1 │ id3858529 │         2 │ 2016-01-19    │ 2016-01-19    │             1 │        -73.98 │         40.76 │        -74.01 │         40.71 │ N            │         2124 │
# => │   │           │           │ 11:35:24      │ 12:10:48      │               │               │               │               │               │              │              │

Title: Filtering Polars DataFrame by Trip Duration (Continued)
Summary
This continues the demonstration of filtering a Polars DataFrame in Nushell based on the 'trip_duration' column. It shows the first two rows of the filtered data where the trip duration is greater than or equal to 500 seconds. The IDs of the trips are 'id2377394' and 'id3858529' with trip durations of 663 and 2124 seconds, respectively.