Skip to main content

Questions tagged [filter]

A program or routine that rejects or accepts data that meets a given criterion. An example would be a filter that removed entries less than a given limit from a set of values. Do NOT use this tag for: Signal or image processing, use [filtering]. Java servlet filters. Use [servlet-filters]. For Bloom filters, use [bloom-filter]. For CSS filters use [css-filters].

1132 votes
20 answers
860k views

List comprehension vs. lambda + filter

I have a list that I want to filter by an attribute of the items. Which of the following is preferred (readability, performance, other reasons)? xs = [x for x in xs if x.attribute == value] xs = ...
Agos's user avatar
  • 19.1k
1083 votes
20 answers
2.4m views

Remove rows with all or some NAs (missing values) in data.frame

I'd like to remove the lines in this data frame that: a) contain NAs across all columns. Below is my example data frame. gene hsap mmul mmus rnor cfam 1 ENSG00000208234 0 NA NA ...
Benoit B.'s user avatar
  • 12k
774 votes
31 answers
883k views

How to filter a Java Collection (based on predicate)?

I want to filter a java.util.Collection based on a predicate.
Kevin Wong's user avatar
  • 14.8k
635 votes
10 answers
533k views

How to filter empty or NULL names in a QuerySet?

I have first_name, last_name & alias (optional) which I need to search for. So, I need a query to give me all the names that have an alias set. Only if I could do: Name.objects.filter(alias!="") ...
Avid Coder's user avatar
  • 18.2k
516 votes
31 answers
656k views

Filter object properties by key in ES6

Let's say I have an object: { item1: { key: 'sdfd', value:'sdfd' }, item2: { key: 'sdfd', value:'sdfd' }, item3: { key: 'sdfd', value:'sdfd' } } I want to create another object by filtering ...
29er's user avatar
  • 8,906
448 votes
2 answers
110k views

Why is `[` better than `subset`?

When I need to filter a data.frame, i.e., extract rows that meet certain conditions, I prefer to use the subset function: subset(airquality, Month == 8 & Temp > 90) Rather than the [ function: ...
flodel's user avatar
  • 88.7k
372 votes
8 answers
346k views

How to use filter, map, and reduce in Python 3

This is how I am accustomed to filter, map, and reduce working in Python 2: >>> def f(x): return x % 2 != 0 and x % 3 != 0 >>> filter(f, range(2, 25)) [5, 7, 11, 13, 17, 19, ...
Dick Lucas's user avatar
  • 12.6k
371 votes
8 answers
410k views

File input 'accept' attribute - is it useful?

Implementing a file upload under html is fairly simple, but I just noticed that there is an 'accept' attribute that can be added to the <input type="file" ...> tag. Is this attribute useful as ...
Darren Oster's user avatar
  • 9,186
345 votes
24 answers
682k views

How to filter an array from all elements of another array

I'd like to understand the best way to filter an array from all elements of another one. I tried with the filter function, but it doesn't come to me how to give it the values i want to remove. ...
Robdll's user avatar
  • 6,135
337 votes
4 answers
305k views

Java 8 Streams: multiple filters vs. complex condition

Sometimes you want to filter a Stream with more than one condition: myList.stream().filter(x -> x.size() > 10).filter(x -> x.isCool()) ... or you could do the same with a complex condition ...
deamon's user avatar
  • 91.3k
335 votes
11 answers
370k views

remove None value from a list without removing the 0 value

This was my source I started with. My List L = [0, 23, 234, 89, None, 0, 35, 9] When I run this : L = filter(None, L) I get this results [23, 234, 89, 35, 9] But this is not what I need, what ...
mongotop's user avatar
  • 5,714
319 votes
5 answers
719k views

Filter rows which contain a certain string

I have to filter a data frame using as criterion those row in which is contained the string RTB. I'm using dplyr. d.del <- df %>% group_by(TrackingPixel) %>% summarise(MonthDelivery = as....
Gianluca's user avatar
  • 6,567
315 votes
1 answer
164k views

How to query Case-insensitive data in Django ORM?

How can I query/filter in Django and ignore the cases of my query-string? I've got something like and like to ignore the case of my_parameter: MyClass.objects.filter(name=my_parameter)
Ron's user avatar
  • 23.1k
307 votes
7 answers
346k views

How to filter a dictionary according to an arbitrary condition function?

I have a dictionary of points, say: >>> points={'a':(3,4), 'b':(1,2), 'c':(5,5), 'd':(3,3)} I want to create a new dictionary with all the points whose x and y value is smaller than 5, i.e. ...
Adam Matan's user avatar
  • 134k
298 votes
3 answers
156k views

How to make Regular expression into non-greedy?

I'm using jQuery. I have a string with a block of special characters (begin and end). I want get the text from that special characters block. I used a regular expression object for in-string finding. ...
Rueta's user avatar
  • 3,507

15 30 50 per page
1
2 3 4 5
2160