multiple-conditions

Efficient conditional summing by multiple conditions in R

折月煮酒 提交于 2019-12-02 15:59:15
问题 I'm struggling with finding an efficient solution for the following problem: I have a large manipulated data frame with around 8 columns and 80000 rows that generally includes multiple data types. I want to create a new data frame that includes the sum of one column if conditions from the large data frame are met. Imagine the head of the original data frame looks like this. The column $years.raw indicates that the company measured data for x years. > cbind(company.raw,years.raw,source,amount

Calculating incremental differences in a given column

对着背影说爱祢 提交于 2019-12-02 13:57:04
问题 i was searching web and stackoverflow but didn,t find an answer. :( So please help me i am still learning and reading, but i am not yet thinking correctly, there are no IF and FOR LOOPs to do stuff. :) I have table1: id| date |state_on_date|year_quantity 1|30.12.2013|23 |100 1|31.12.2013|25 |100 1|1.1.2014 |35 |150 1|2.1.2014 |12 |150 2|30.12.2013|34 |200 2|31.12.2013|65 |200 2|1.1.2014 |43 |300 I am trying to get: table2: id| date |state_on_date|year_quantity|state_on_date_compare 1|30.12

Efficient conditional summing by multiple conditions in R

孤街醉人 提交于 2019-12-02 12:02:17
I'm struggling with finding an efficient solution for the following problem: I have a large manipulated data frame with around 8 columns and 80000 rows that generally includes multiple data types. I want to create a new data frame that includes the sum of one column if conditions from the large data frame are met. Imagine the head of the original data frame looks like this. The column $years.raw indicates that the company measured data for x years. > cbind(company.raw,years.raw,source,amount.inkg) company.raw years.raw source amount.inkg [1,] "C1" "1" "Ink" "5" [2,] "C1" "1" "Recycling" "2" [3

awk two regex conditions - structure convoluted complex transactions list csv

ぃ、小莉子 提交于 2019-12-02 04:43:20
My original input files is a booking transaction list. I am interested in the lines that are in the two sections: a) transactions and b) refunds. These are always at the bottom of the CSVs and structured. I can skip all lines above section transaction via regex condition /transaction/ {print}. I would like to add a column with strings "transaction or refunds" depending on the section in the csv. So I know if a cloumn is a transactions or refund. something like IF ($2 = "transaction" || " " != "refunds"){$7=="transaction"}; IF ($2 = "refunds" || " " != "transaction"){$7=="refunds"} I share the

Calculating incremental differences in a given column

丶灬走出姿态 提交于 2019-12-02 03:55:58
i was searching web and stackoverflow but didn,t find an answer. :( So please help me i am still learning and reading, but i am not yet thinking correctly, there are no IF and FOR LOOPs to do stuff. :) I have table1: id| date |state_on_date|year_quantity 1|30.12.2013|23 |100 1|31.12.2013|25 |100 1|1.1.2014 |35 |150 1|2.1.2014 |12 |150 2|30.12.2013|34 |200 2|31.12.2013|65 |200 2|1.1.2014 |43 |300 I am trying to get: table2: id| date |state_on_date|year_quantity|state_on_date_compare 1|30.12.2013| 23 |100 |23 1|31.12.2013| 25 |100 |-2 1|1.1.2014 | 35 |150 |-10 1|2.1.2014 | 12 |150 |23 2|30.12

LINQ: Split Where OR conditions

回眸只為那壹抹淺笑 提交于 2019-12-01 17:13:04
问题 So I have the following where conditions sessions = sessions.Where(y => y.session.SESSION_DIVISION.Any(x => x.DIVISION.ToUpper().Contains(SearchContent)) || y.session.ROOM.ToUpper().Contains(SearchContent) || y.session.COURSE.ToUpper().Contains(SearchContent)); I want to split this into multiple lines based on whether a string is empty for example: if (!String.IsNullOrEmpty(Division)) { sessions = sessions.Where(y => y.session.SESSION_DIVISION.Any(x => x.DIVISION.ToUpper().Contains

Pandas: np.where with multiple conditions on dataframes

冷暖自知 提交于 2019-12-01 04:40:17
hi folks i have look all over SO and google and cant find anything similar... I have a dataframe x (essentially consisting of one row and 300 columns) and another dataframe y with same size but different data. I would like to modify x such that it is 0 if it has a different sign to y AND x itself is not 0, else leave it as it is. so this requires the use of np.where with multiple conditions. However the multiple condition examples i've seen all use scalars, and when i use the same syntax it does not seem to work (ends up setting -everything- to zero, no error). i'm worried about assign-by

Pandas: np.where with multiple conditions on dataframes

孤者浪人 提交于 2019-12-01 02:15:09
问题 hi folks i have look all over SO and google and cant find anything similar... I have a dataframe x (essentially consisting of one row and 300 columns) and another dataframe y with same size but different data. I would like to modify x such that it is 0 if it has a different sign to y AND x itself is not 0, else leave it as it is. so this requires the use of np.where with multiple conditions. However the multiple condition examples i've seen all use scalars, and when i use the same syntax it

Multiple 'or' condition in Python [duplicate]

别来无恙 提交于 2019-11-30 06:38:05
This question already has an answer here: How to test multiple variables against a value? 22 answers 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 fields[9] != 'R': Thank you. Use not in and a sequence: if fields[9] not in ('A', 'D', 'E', 'N', 'R'): which tests against a tuple, which Python will conveniently and efficiently store as one constant. You could also use a set literal: if fields[9] not

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

我们两清 提交于 2019-11-27 23:10:21
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", "drive", "ferry") > kids <- c("Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No", "Yes", "No", "Yes") > distance <- c(1, 12, 5, 25, 7, 2, "", 8, 19, 7, "", 4, 16, 12, 7) > > df = data.frame(commute, kids, distance) > df commute kids distance 1 walk Yes 1 2 bike Yes 12 3 subway No 5 4 drive No 25 5 ferry Yes 7 6 walk Yes 2 7