[Python] Create unique id column for each pair of (col_x, col_y) in polars Python

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024.

  1. Stack

    Stack Membro Participativo

    I have a polars dataframe with subject_id, timestamp, event, col1, and col2 columns.

    I want to split this dataframe into two polars dataframe (one with subject_id, timestamp, event and one with subject_id, timestamp, col1, col2), but create a column for a unique id before splitting such that I can use that id to join the split dataframes after grouping/manipulating separately.

    How can I create this unique id column in polars where there is a unique id for every unique subject_id, timestamp pair in the dataframe before splitting?

    Essentially, I wish to do what this post provided, but in Polars. I understand Polars does not have indexes, so what is the best approach?

    Continue reading...

Compartilhe esta Página