Questions tagged [filtering]
Filtering is selecting a subset of some set of data based on various criteria. In signal processing, it is the complete or partial suppression of some aspect of the signal. Use this tag for questions asking for help with filtering datasets.
filtering
7,745
questions
1138
votes
13
answers
1.3m
views
How to get first N number of elements from an array
I am working with Javascript(ES6) /FaceBook react and trying to get the first 3 elements of an array that varies in size. I would like do the equivalent of Linq take(n).
In my Jsx file I have the ...
863
votes
12
answers
1.2m
views
How to filter Pandas dataframe using 'in' and 'not in' like in SQL
How can I achieve the equivalents of SQL's IN and NOT IN?
I have a list with the required values. Here's the scenario:
df = pd.DataFrame({'country': ['US', 'UK', 'Germany', 'China']})
...
853
votes
14
answers
2.4m
views
Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
I want to filter my dataframe with an or condition to keep rows with a particular column's values that are outside the range [-0.25, 0.25]. I tried:
df = df[(df['col'] < -0.25) or (df['col'] > 0....
457
votes
12
answers
434k
views
How to filter an associative array comparing keys with values in an indexed array?
The callback function in array_filter() only passes in the array's values, not the keys.
If I have:
$my_array = array("foo" => 1, "hello" => "world");
$allowed = ...
399
votes
26
answers
306k
views
Creating a blurring overlay view
In the Music app of the new iOS, we can see an album cover behind a view that blurs it.
How can something like that be accomplished? I've read the documentation, but did not find anything there.
396
votes
18
answers
626k
views
Detect and exclude outliers in a pandas DataFrame
I have a pandas dataframe with few columns.
Now I know that certain rows are outliers based on a certain column value.
For instance
column Vol has all values around 12xx and one value is 4000 (outlier)...
367
votes
20
answers
773k
views
JavaScript: filter() for Objects
ECMAScript 5 has the filter() prototype for Array types, but not Object types, if I understand correctly.
How would I implement a filter() for Objects in JavaScript?
Let's say I have this object:
...
361
votes
9
answers
331k
views
mongodb/mongoose findMany - find all documents with IDs listed in array
I have an array of _ids and I want to get all docs accordingly, what's the best way to do it ?
Something like ...
// doesn't work ... of course ...
model.find({
'_id' : [
'...
348
votes
16
answers
903k
views
Filtering Pandas DataFrames on dates
I have a Pandas DataFrame with a 'date' column. Now I need to filter out all rows in the DataFrame that have dates outside of the next two months. Essentially, I only need to retain the rows that are ...
298
votes
4
answers
502k
views
Logical operators for Boolean indexing in Pandas
I'm working with a Boolean index in Pandas.
The question is why the statement:
a[(a['some_column']==some_number) & (a['some_other_column']==some_other_number)]
works fine whereas
a[(a['...
187
votes
9
answers
377k
views
Filtering collections in C#
I am looking for a very fast way to filter down a collection in C#. I am currently using generic List<object> collections, but am open to using other structures if they perform better.
...
173
votes
8
answers
167k
views
Checking if ANY of an array's elements are in another array
I have two arrays in PHP as follows:
People:
Array
(
[0] => 3
[1] => 20
)
Wanted Criminals:
Array
(
[0] => 2
[1] => 4
[2] => 8
[3] => 11
[4] => 12
...
154
votes
9
answers
97k
views
Is there a way to filter network requests using Google Chrome developer tools?
Is it possible to filter out some requests using Chrome developer tools, say, filter out all image requests?
140
votes
6
answers
216k
views
filter items in a python dictionary where keys contain a specific string
I'm a C coder developing something in python. I know how to do the following in C (and hence in C-like logic applied to python), but I'm wondering what the 'Python' way of doing it is.
I have a ...
139
votes
12
answers
258k
views
Datatables - Search Box outside datatable
I'm using DataTables (datatables.net) and I would like my search box to be outside of the table (for example in my header div).
Is this possible ?
110
votes
1
answer
251k
views
Creating lowpass filter in SciPy - understanding methods and units
I am trying to filter a noisy heart rate signal with python. Because heart rates should never be above about 220 beats per minute, I want to filter out all noise above 220 bpm. I converted 220/minute ...
108
votes
8
answers
129k
views
Filtering multiple items in a multi-index Pandas dataframe
I have the following table:
Area
NSRCODE PBL_AWI
CM BONS 44705.492941
BTNN 253854.591990
FONG 41625....
107
votes
7
answers
191k
views
How can I filter an ArrayList in Kotlin so I only have elements which match my condition?
I have an array:
var month: List<String> = arrayListOf("January", "February", "March")
I have to filter the list so I am left with only "January".
103
votes
11
answers
528k
views
How to run a SQL query on an Excel table?
I'm trying to create a sub-table from another table of all the last name fields sorted A-Z which have a phone number field that isn't null. I could do this pretty easy with SQL, but I have no clue how ...
100
votes
4
answers
175k
views
Remove rows not .isin('X') [duplicate]
Sorry just getting into Pandas, this seems like it should be a very straight forward question. How can I use the isin('X') to remove rows that are in the list X? In R I would write !which(a %in% b).
100
votes
7
answers
135k
views
Filtering out values from a C# Generic Dictionary
I have a C# dictionary, Dictionary<Guid, MyObject> that I need to be filtered based on a property of MyObject.
For example, I want to remove all records from the dictionary where MyObject....
95
votes
10
answers
91k
views
Remove all elements from array that do not start with a certain string
I have an array that looks like this:
array(
'abc' => 0,
'foo-bcd' => 1,
'foo-def' => 1,
'foo-xyz' => 0,
// ...
)
How can I retain only the elements that start with foo-?
86
votes
2
answers
115k
views
Efficient thresholding filter of an array with numpy
I need to filter an array to remove the elements that are lower than a certain threshold. My current code is like this:
threshold = 5
a = numpy.array(range(10)) # testing data
b = numpy.array(filter(...
82
votes
12
answers
208k
views
How can I return the difference between two lists?
I have two array lists e.g.
List<Date> a;
contains : 10/10/2014, 10/11/2016
List<Date> b;
contains : 10/10/2016
How can i do a check between list a and b so the value that is missing ...
82
votes
3
answers
71k
views
Pandas equivalent of GROUP BY HAVING in SQL
What is the most efficient way to use groupby and in parallel apply a filter in pandas?
Basically I am asking for the equivalent in SQL of
select *
...
group by col_name
having condition
I think ...
79
votes
5
answers
92k
views
How do I filter a pandas DataFrame based on value counts?
I'm working in Python with a pandas DataFrame of video games, each with a genre. I'm trying to remove any video game with a genre that appears less than some number of times in the DataFrame, but I ...
76
votes
8
answers
209k
views
Filtering array of objects with lodash based on property value
We have an array of objects as such
var myArr = [ {name: "john", age: 23},
{name: "john", age: 43},
{name: "jim", age: 101},
{name: "bob", age: 67} ];
how ...
76
votes
4
answers
57k
views
Case-insensitive version of array_search()
I have an array like this:
$array = ['oooo', 'no', 'mmmm', 'yes'];
I'd like to search for a word "yes". I know about array_search(), but I'd like to match "yes", "Yes" ...
76
votes
6
answers
50k
views
How to filter docker process based on image
I have been trying to get the container id of docker instance using docker process command, but when i'm trying with filter by name it works fine for me.
sudo -S docker ps -q --filter="name=...
72
votes
3
answers
101k
views
Eliminating all data over a given percentile
I have a pandas DataFrame called data with a column called ms. I want to eliminate all the rows where data.ms is above the 95% percentile. For now, I'm doing this:
limit = data.ms.describe(90)['95%'...
72
votes
8
answers
92k
views
Can Java 8 Streams operate on an item in a collection, and then remove it?
Like just about everyone, I'm still learning the intricacies (and loving them) of the new Java 8 Streams API. I have a question concerning usage of streams. I'll provide a simplified example.
Java ...
60
votes
7
answers
213k
views
How do I remove all zero elements from a NumPy array?
I have a rank-1 numpy.array of which I want to make a boxplot. However, I want to exclude all values equal to zero in the array. Currently, I solved this by looping the array and copy the value to a ...
59
votes
11
answers
161k
views
Most efficient way to search for object in an array by a specific property's value
What would be the fastest, most efficient way to implement a search method that will return an object with a qualifying id?
Sample object array:
$array = [
(object) ['id' => 'one', 'color' =>...
58
votes
5
answers
60k
views
How to filter parameters in rails?
Rails has built in log filtering so you don't log passwords and credit cards. Works great for that but when you want to trigger a custom log (like to email) and send your own params or other data ...
58
votes
7
answers
39k
views
Filtering ZSH history by command
I was told that in ZSH you could do something like command and then when you hit up it would filter the history based on the given command. But when I try this it just cycles the history like bash ...
56
votes
3
answers
55k
views
Django excluding specific instances from queryset without using field lookup
I sometimes have the need to make sure some instances are excluded from a queryset.
This is the way I do it usually:
unwanted_instance = MyModel.objects.get(pk=bad_luck_number)
...
54
votes
1
answer
68k
views
How to filter a vector of custom structs?
I am trying to filter a Vec<Vocabulary> where Vocabulary is a custom struct, which itself contains a struct VocabularyMetadata and a Vec<Word>:
#[derive(Serialize, Deserialize)]
pub ...
53
votes
8
answers
147k
views
How to search an Amazon S3 Bucket using Wildcards?
This stackoverflow answer helped a lot. However, I want to search for all PDFs inside a given bucket.
I click "None".
Start typing.
I type *.pdf
Press Enter
Nothing happens. Is there a way to use ...
53
votes
8
answers
112k
views
Filtering os.walk() dirs and files
I'm looking for a way to include/exclude files patterns and exclude directories from a os.walk() call.
Here's what I'm doing by now:
import fnmatch
import os
includes = ['*.doc', '*.odt']
excludes = [...
52
votes
8
answers
64k
views
Adding the current date with Maven2 filtering
I have a Maven2 project, and I need to add, in a properties file, the current version and the current date.
For the current version, I've used ${project.version}, which works correctly.
My question ...
50
votes
2
answers
30k
views
How to dynamically do filtering in Java 8?
I know in Java 8, I can do filtering like this :
List<User> olderUsers = users.stream().filter(u -> u.age > 30).collect(Collectors.toList());
But what if I have a collection and half a ...
49
votes
9
answers
101k
views
Filtering array of objects with arrays based on nested value
I am trying to filter an array, based on some nested object. I prepared some Fiddle
Input array looks like this:
let arrayOfElements =
[
{
"name": "a",
"...
47
votes
9
answers
64k
views
Get the difference between two 2-dimensional arrays (each containing a single column of values)
I have an array containing rows of associative data.
$array1 = array(
array('ITEM' => 1),
array('ITEM' => 2),
array('ITEM' => 3),
);
I have a second array, also containing rows ...
46
votes
7
answers
25k
views
Android LogCat Filter for multiple tags in Eclipse
Clicked on create filter could not figure out from docs how to create a filter for say two or more tags. If I have two tags com.test.TestClassA and com.test.TestClassB how do I create a filter that ...
44
votes
16
answers
69k
views
Fastest Gaussian blur implementation
How do you implement the fastest possible Gaussian blur algorithm?
I am going to implement it in Java, so GPU solutions are ruled out. My application, planetGenesis, is cross platform, so I don't ...
43
votes
2
answers
58k
views
Remove spurious small islands of noise in an image - Python OpenCV
I am trying to get rid of background noise from some of my images. This is the unfiltered image.
To filter, I used this code to generate a mask of what should remain in the image:
element = cv2....
42
votes
12
answers
47k
views
Explode string into array with no empty elements?
PHP's explode function returns an array of strings split on some provided substring. It will return empty strings when there are leading, trailing, or consecutive delimiters, like this:
var_dump(...
42
votes
3
answers
27k
views
How to filter a list in-place with Kotlin?
In Java I can remove items from a list with this code:
private void filterList(List<Item> items) {
Iterator<Item> iterator = items.iterator();
while (iterator.hasNext()) {
...
41
votes
1
answer
69k
views
How to filter for unique combination of columns from an R dataframe
I am trying to filter out the duplicates of a subset of columns from a dataframe in R.
I am interested in filtering unique combinations of session, first, and last. The following is what my data ...
40
votes
5
answers
51k
views
Get the difference of two arrays of objects by comparing values from a particular column/property
I know there is array_diff and array_udiff for comparing the difference between two arrays, but how would I do it with two arrays of objects?
array(4) {
[0]=>
object(stdClass)#32 (9) {
...