Skip to content
Advertisement

Filter pandas column based on ranges in a huge list

Trying to filter ‘time’ data into ‘time_filtered’ based on lut_lst ranges, ergo if ‘time’ value falls in any of the ranges, exchange with NaN otherwise copy value into new column.

JavaScript

The output for df is not filtered. I tried using any(lut_lst) or all(lut_lst) but that just threw an error.

JavaScript

Advertisement

Answer

Use tuples instead of ranges in lut_lst, and change your filter slightly:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement