#๐Ÿ”’ Polars help

10 messages ยท Page 1 of 1 (latest)

quaint trellis
#

Hi, so I've got a dataframe in polars here one column is 'offRoad' being a bool. I want to keep only rows where offRoad is False and rows where offRoad is True but part of a group of offRoads of at least 4 consecutive Trues.

I really hope that makes sense. I'm quite new to Polars, but got a decent grip on python and could make this work by iterating through the rows. But I was hoping someone would have a suggestion on how I could do this in a more 'Polarsy' way using streams or whatnot.

Thanks in advance.

slate lightBOT
#

@quaint trellis

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quaint trellis
#

In other words I want to remove rows where offRoad is true but not part of a group of at least 4 consecutive trues.

stark stirrup
# quaint trellis Hi, so I've got a dataframe in polars here one column is 'offRoad' being a bool....

oh hey, welcome the the polars cult, you can't escape now /s
anyways, I'd probably do a .shift() then !=; this would allow you to find where a value switches from True -> False or vice versa; do a .cumsum on this to get consec_group_ids where each group is some consecutive Trues or Falses
then, say, find the .max of the .cumsum .over the consec_group_id on offRoad, and know you'll know how long each consecutive value sequence is; .filter accordingly

#

scratch that, rle_id exists

long mountain
#

there is an official polars discord server btw, you can ask in #data-science-and-ml or it if you don't get answers in python-help

slate lightBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.