[Python] Combination of piso functions to create dataframe of last inspection dates for...

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm struggling with the right combo of piso functions to perform the following analysis:

    Let's say I have a length of road with mile markers as such:

    0---1---2---3---4---5

    And let's say I have a record of inspections like so:

    (mile 0 to 5 inspected 1/1/2025)

    (mile 2 to 5 inspected 1/8/2025)

    (mile 0 to 3 inspected 1/15/2025)

    (mile 0 to 2 inspected 1/22/2025)

    The table/dataframe "all_df" representing these inspections would look like:

    import pandas as pd

    all_df = pd.DataFrame(
    data=(
    (0, 5, pd.Timestamp("2025-1-1")),
    (2, 5, pd.Timestamp("2025-1-8")),
    (0, 3, pd.Timestamp("2025-1-15")),
    (0, 2, pd.Timestamp("2025-1-22")),
    ),
    columns = ["From_Mi", "To_Mi", "Date"]
    )


    The desired dataframe "recent_df" showing only most recent inspections would look like:

    | From_MI | To_Mi | Last Date |
    | ------- | ----- | --------- |
    | 0 | 2 | 1/22/2025 |
    | 2 | 3 | 1/15/2025 |
    | 3 | 5 | 1/8/2025 |


    Would this be some operation involving .split() and .intersection()?

    Any help is appreciated!

    Continue reading...

Compartilhe esta Página