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

How to keep substring until character is found in Polars DataFrame?

$
0
0

I am working with a Polars DataFrame that contains a column with values like this:

shape: (3, 2)┌──────────────┬──────────────┐│      A       │      B       ││     ---      │     ---      ││     str      │     str      │├──────────────┼──────────────┤│  A|B:0d:cs   │    C:2ew2    │├──────────────┼──────────────┤│    A:1ds0    │   E|F:91we23 │├──────────────┼──────────────┤│ QW|P:3dwsd   │   A|Z:12w219 │└──────────────┴──────────────┘

I want to extract the left substring from each cell in the DataFrame until I find the character ":". The desired result should look like this:

shape: (3, 2)┌──────────────┬──────────────┐│      A       │      B       ││     ---      │     ---      ││     str      │     str      │├──────────────┼──────────────┤│     A|B      │      C       │├──────────────┼──────────────┤│      A       │     E|F      │├──────────────┼──────────────┤│    QW|P      │     A|Z      │└──────────────┴──────────────┘

Thank you for your help in advance!


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>