multiple-columns

Testing for multiple identical columns in R

一个人想着一个人 提交于 2020-12-30 17:21:50
问题 Is there a short way to test for identity over multiple columns? For example, over this input data=data.table(one=c(1,2,3,4), two=c(7,8,9,10), three=c(1,2,3,4), four=c(1,2,3,4) ) Is there something that would return all the columns that are identical to data$one? Something like allcolumnsidentity(data$one, data) # compares all columns with respect to data$one Should return (TRUE, FALSE, TRUE, TRUE) since data$three and data$four are identical to data$one. I saw the identical() and comapre()

Testing for multiple identical columns in R

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-30 17:10:55
问题 Is there a short way to test for identity over multiple columns? For example, over this input data=data.table(one=c(1,2,3,4), two=c(7,8,9,10), three=c(1,2,3,4), four=c(1,2,3,4) ) Is there something that would return all the columns that are identical to data$one? Something like allcolumnsidentity(data$one, data) # compares all columns with respect to data$one Should return (TRUE, FALSE, TRUE, TRUE) since data$three and data$four are identical to data$one. I saw the identical() and comapre()

how to rename columns in pandas using a list

别说谁变了你拦得住时间么 提交于 2020-12-30 08:17:11
问题 I have a dataframe (df) that has 44 columns and I want to rename columns 2:44. I have a list (namesList) of length 42 that has the new column names. I then try to rename my columns by using the list: df.columns[2:len(df.columns)] = namesList However I get the error: TypeError: Index does not support mutable operations Why do I get this error? 回答1: You need generate new columns names - first and second value from old one and another from list : df.columns = df.columns[:2].tolist() + namesList

how to rename columns in pandas using a list

ぃ、小莉子 提交于 2020-12-30 08:14:55
问题 I have a dataframe (df) that has 44 columns and I want to rename columns 2:44. I have a list (namesList) of length 42 that has the new column names. I then try to rename my columns by using the list: df.columns[2:len(df.columns)] = namesList However I get the error: TypeError: Index does not support mutable operations Why do I get this error? 回答1: You need generate new columns names - first and second value from old one and another from list : df.columns = df.columns[:2].tolist() + namesList

how to rename columns in pandas using a list

微笑、不失礼 提交于 2020-12-30 08:14:13
问题 I have a dataframe (df) that has 44 columns and I want to rename columns 2:44. I have a list (namesList) of length 42 that has the new column names. I then try to rename my columns by using the list: df.columns[2:len(df.columns)] = namesList However I get the error: TypeError: Index does not support mutable operations Why do I get this error? 回答1: You need generate new columns names - first and second value from old one and another from list : df.columns = df.columns[:2].tolist() + namesList

Pandas - combine row dates with column times

半腔热情 提交于 2020-12-11 08:57:52
问题 I have a dataframe: Date 0:15 0:30 0:45 ... 23:15 23:30 23:45 24:00 2004-05-01 3.74618 3.58507 3.30998 ... 2.97236 2.92008 2.80101 2.6067 2004-05-02 3.09098 3.84625 3.54672 ... 2.83725 2.93876 2.82762 2.6255 How do I convert it to: Date value 2004-05-01 0:15 3.74618 2004-05-01 0:30 3.58507 2004-05-01 0:45 3.30998 ... I wrote some code which does work, but I'm sure it's possible to do the same in more elegant couple of lines code cols = [] for col in frame.columns.values: if col != '24:00': dt