Home Explore Blog CI



nushell

4th chunk of `cookbook/polars_v_pandas_v_nushell.md`
8dc86bba23dcafe83fba3162baba0694012877dae30c0bb60000000100001337
# => ╭───┬───────────┬───────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬──────────────┬──────────────╮
# => │ # │    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 │ id2875421 │         2 │ 2016-03-14    │ 2016-03-14    │             1 │        -73.98 │         40.77 │        -73.96 │         40.77 │ N            │         7.58 │
# => │   │           │           │ 17:24:55      │ 17:32:30      │               │               │               │               │               │              │              │
# => │ 1 │ id2377394 │         1 │ 2016-06-12    │ 2016-06-12    │             1 │        -73.98 │         40.74 │        -74.00 │         40.73 │ N            │        11.05 │
# => │   │           │           │ 00:43:35      │ 00:54:38      │               │               │               │               │               │              │              │
# => │ 2 │ id3858529 │         2 │ 2016-01-19    │ 2016-01-19    │             1 │        -73.98 │         40.76 │        -74.01 │         40.71 │ N            │        35.40 │
# => │   │           │           │ 11:35:24      │ 12:10:48      │               │               │               │               │               │              │              │
# => │ 3 │ id3504673 │         2 │ 2016-04-06    │ 2016-04-06    │             1 │        -74.01 │         40.72 │        -74.01 │         40.71 │ N            │         7.15 │
# => │   │           │           │ 19:32:31      │ 19:39:40      │               │               │               │               │               │              │              │
# => │ 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 │

Title: Filtering Polars DataFrame by Trip Duration in Nushell
Summary
This section demonstrates how to filter a Polars DataFrame in Nushell to retain only rows where the 'trip_duration' is greater than or equal to 500 seconds. The `polars filter-with` command is used with a condition that checks if the 'trip_duration' column meets the specified criteria. The `first 5` and `collect` commands are used to display the first 5 rows of the filtered DataFrame.