3 ms·
Yesterday I spent over 45 mins dealing with this error: https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas https://
by d4rkp4ttern 4y ago
Yesterday I spent over 45 mins dealing with this error:
https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas https://stackoverflow.com/questions/20625582/how-to-deal-wit...
“SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.”
- brahbrah 4y agoSo in pandas you might get that warning when you’re trying to do an in place operation like so: df.loc['2023-01-01': '2023-12-31'] *= 2 This doubles every row in 2023 in your frame. In polars there’s no mutating operations, everything is pure, so you won’t see any warnings of that nature, but what you will see instead is having to do something like this to solve the same problem: df.with_column([ pl.when(pl.col('date').is_between( datetime(2023, 1, 1), datetime(2023, 12, 31), )).then(pl.col(x) * 2) .otherwise(pl.col(x)) .alias(x) for x in df.columns if x != 'date' ]) So there’s definitely some trade offs, but mutating operations are sometimes worth learning how to use them properly to avoid that pandas warning (or know when to ignore it, because unfortunately there can be false positives).
- kristianp 4y agoWhen I saw your comment I thought, oh there's another story about polars! Turns out you can reply to a 13 day old thread.