Questions tagged [multiple-conditions]

Examples include if, for, while and other loops.

while (a==1 && b==2)
{
   ...
}

The loop will continue as long as a is 1 and b is 2.

630 questions
102
votes
7 answers

Filter multiple values on a string column in dplyr

I have a data.frame with character data in one of the columns. I would like to filter multiple options in the data.frame from the same column. Is there an easy way to do this that I'm missing? Example: data.frame name = dat days name 88 …
Tom O
  • 1,497
  • 3
  • 13
  • 16
66
votes
10 answers

What is better: multiple "if" statements or one "if" with multiple conditions?

For my work I have to develop a small Java application that parses very large XML files (~300k lines) to select very specific data (using Pattern), so I'm trying to optimize it a little. I was wondering what was better between these 2 snippets: if…
3rgo
  • 3,115
  • 7
  • 31
  • 44
57
votes
3 answers

LINQ Joining in C# with multiple conditions

I have a LINQ Joining statement in C# with multiple conditions. var possibleSegments = from epl in eventPotentialLegs join sd in segmentDurations on new { epl.ITARequestID, epl.ITASliceNumber, …
Ratheesh
  • 571
  • 1
  • 4
  • 3
51
votes
3 answers

Scala filter on two conditions

I would like to filter my data set on two conditions at once. Is it possible? I want something like this: mystuff = mystuff.filter(_.isX && _.name == "xyz")
richsoni
  • 4,188
  • 8
  • 34
  • 47
27
votes
2 answers

Multiple 'or' condition in Python

I have a little code issue and it works with IDLE and not with Eclipse, can I write this : if fields[9] != ('A' or 'D' or 'E' or 'N' or 'R'): instead of this : if fields[9] != 'A' and fields[9] != 'D' and fields[9] != 'E' and fields[9] != 'N' and…
katze
  • 1,273
  • 3
  • 16
  • 24
24
votes
3 answers

C++: Multiple exit conditions in for loop (multiple variables): AND -ed or OR -ed?

For loops and multiple variables and conditions. I am using a for loop to set source and destination indexes to copy items in an array. for(int src = 0, dst = 8; src < 8, dst >= 0; src ++, dst --) { arr2[dst] = arr1[src]; } Something…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
23
votes
3 answers

XPATH Multiple Element Filters

I have the following sample XML structure: yes no no
CroweMan
13
votes
2 answers

mongodb multiple match conditions and return documents with common name

below data is present in "examSheet" collection {"name":"a1", "std":"9", "year":"2017", "exam":"halfyr_T", "marks":[{"p":"45","m":"40","c":"50"}]} {"name":"a1", "std":"9", "year":"2017", "exam":"halfyr_P",…
13
votes
3 answers

How do I create a new column based on multiple conditions from multiple columns?

I'm trying add a new column to a data frame based on several conditions from other columns. I have the following data: > commute <- c("walk", "bike", "subway", "drive", "ferry", "walk", "bike", "subway", "drive", "ferry", "walk", "bike", "subway",…
13
votes
2 answers

WHERE clause with nested multiple conditions

I want to retrieve data with conditions in WHERE clause. Here is my table something look like: Name Location Age ---------------------- AAA Bhuj 24 BBB Mumbai 22 CCC Bhuj 18 DDD Bhuj 27 EEE Mumbai …
Himanshu
  • 31,810
  • 31
  • 111
  • 133
11
votes
4 answers

Which of "and" or "or" should I use to join non-equality checks, and why?

This is a very simple dice roll program that keeps rolling two dice until it gets double sixes. So my while statement is structured as: while DieOne != 6 and DieTwo != 6: For some reason, the program ends as soon as DieOne gets a six. DieTwo is not…
ghulseman
  • 125
  • 1
  • 1
  • 7
9
votes
4 answers

Ruby - Using multiple conditions on a single line

So, I'm running into this issue wherein I want to have three conditions be checked before the routine continues, but it keeps throwing up syntax errors saying it didn't expect the multiple conditions. Now, I know I've seen other people use lines…
8
votes
2 answers

How to efficiently fillna(0) if series is all-nan, or else remaining non-nan entries are zero?

Given that I have a pandas Series, I want to fill the NaNs with zero if either all the values are NaN or if all the values are either zero or NaN. For example, I would want to fill the NaNs in the following Series with zeroes. 0 0 1 0 2…
8
votes
3 answers

pandas: filter group by multiple conditions?

I have a data frame that looks like this: df = pd.DataFrame([ {'id': 123, 'date': '2016-01-01', 'is_local': True }, {'id': 123, 'date': '2017-01-01', 'is_local': False }, {'id': 124, 'date': '2016-01-01', 'is_local': True }, {'id': 124,…
Richard
  • 62,943
  • 126
  • 334
  • 542
8
votes
4 answers

python lambda list filtering with multiple conditions

My understanding about filtering lists with lambda is that the filter will return all the elements of the list that return True for the lambda function. In that case, for the following code, inputlist = [] inputlist.append(["1", "2", "3",…
user3300676
  • 307
  • 2
  • 3
  • 8
1
2 3
41 42