Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

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

$
0
0

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?


Viewing all articles
Browse latest Browse all 13981

Trending Articles