multiple-columns

Apply pandas function to column to create multiple new columns?

夙愿已清 提交于 2019-11-26 13:56:34
How to do this in pandas: I have a function extract_text_features on a single text column, returning multiple output columns. Specifically, the function returns 6 values. The function works, however there doesn't seem to be any proper return type (pandas DataFrame/ numpy array/ Python list) such that the output can get correctly assigned df.ix[: ,10:16] = df.textcol.map(extract_text_features) So I think I need to drop back to iterating with df.iterrows() , as per this ? UPDATE: Iterating with df.iterrows() is at least 20x slower, so I surrendered and split out the function into six distinct

Read CSV file column by column

怎甘沉沦 提交于 2019-11-26 12:41:59
问题 I want to read specific columns from a multi column csv file and print those columns in other csv file using Java. Any help please? Following is my code to print each token line by line..But I am looking to print only few columns out of the multi column csv. import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class ParseCSV { public static void main(String[] args) { try { //csv file containing data String strFile = \"C:

Apply a function to a subset of data.table columns, by column-indices instead of name

筅森魡賤 提交于 2019-11-26 12:06:55
问题 I\'m trying to apply a function to a group of columns in a large data.table without referring to each one individually. a <- data.table( a=as.character(rnorm(5)), b=as.character(rnorm(5)), c=as.character(rnorm(5)), d=as.character(rnorm(5)) ) b <- c(\'a\',\'b\',\'c\',\'d\') with the MWE above, this: a[,b=as.numeric(b),with=F] works, but this: a[,b[2:3]:=data.table(as.numeric(b[2:3])),with=F] doesn\'t work. What is the correct way to apply the as.numeric function to just columns 2 and 3 of a

Assign unique ID based on two columns [duplicate]

孤者浪人 提交于 2019-11-26 11:22:45
问题 This question already has an answer here: Add ID column by group [duplicate] 4 answers How to create a consecutive index based on a grouping variable in a dataframe 6 answers I have a dataframe (df) that looks like this: School Student Year A 10 1999 A 10 2000 A 20 1999 A 20 2000 A 20 2001 B 10 1999 B 10 2000 And I would like to create a person ID column so that df looks like this: ID School Student Year 1 A 10 1999 1 A 10 2000 2 A 20 1999 2 A 20 2000 2 A 20 2001 3 B 10 1999 3 B 10 2000 In

How to print third column to last column?

孤街浪徒 提交于 2019-11-26 10:09:23
问题 I\'m trying to remove the first two columns (of which I\'m not interested in) from a DbgView log file. I can\'t seem to find an example that prints from column 3 onwards until the end of the line. Note that each line has variable number of columns. 回答1: ...or a simpler solution: cut -f 3- INPUTFILE just add the correct delimiter (-d) and you got the same effect. 回答2: awk '{for(i=3;i<=NF;++i)print $i}' 回答3: awk '{ print substr($0, index($0,$3)) }' solution found here: http://www.linuxquestions

Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead

时间秒杀一切 提交于 2019-11-26 08:31:55
问题 I am new in Binding and WPF recently I\'ve learned how to create a listBox with multiple columns using Binding tech <ListView ItemsSource=\"{Binding Items}\" Margin=\"306,70,22,17\" MouseDoubleClick=\"listBoxSS_MouseDoubleClick\" Name=\"listBoxSS\" > <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header=\"first_name \" Width=\"100\" DisplayMemberBinding=\"{Binding Path=First_name}\" /> <GridViewColumn Header=\"last_name\" Width=\"100\" DisplayMemberBinding=\"{Binding Path=Last

apply a function over groups of columns

时光怂恿深爱的人放手 提交于 2019-11-26 08:24:55
问题 How can I use apply or a related function to create a new data frame that contains the results of the row averages of each pair of columns in a very large data frame? I have an instrument that outputs n replicate measurements on a large number of samples, where each single measurement is a vector (all measurements are the same length vectors). I\'d like to calculate the average (and other stats) on all replicate measurements of each sample. This means I need to group n consecutive columns

Scrolling a flexbox with overflowing content

ぐ巨炮叔叔 提交于 2019-11-26 07:50:47
问题 Here\'s the code I\'m using to achieve the above layout: .header { height: 50px; } .body { position: absolute; top: 50px; right: 0; bottom: 0; left: 0; display: flex; } .sidebar { width: 140px; } .main { flex: 1; display: flex; flex-direction: column; } .content { flex: 1; display: flex; } .column { padding: 20px; border-right: 1px solid #999; } <div class=\"header\">Main header</div> <div class=\"body\"> <div class=\"sidebar\">Sidebar</div> <div class=\"main\"> <div class=\"page-header\"

Combine two or more columns in a dataframe into a new column with a new name

谁说我不能喝 提交于 2019-11-26 07:29:43
问题 For example if I have this: n = c(2, 3, 5) s = c(\"aa\", \"bb\", \"cc\") b = c(TRUE, FALSE, TRUE) df = data.frame(n, s, b) n s b 1 2 aa TRUE 2 3 bb FALSE 3 5 cc TRUE Then how do I combine the two columns n and s into a new column named x such that it looks like this: n s b x 1 2 aa TRUE 2 aa 2 3 bb FALSE 3 bb 3 5 cc TRUE 5 cc 回答1: Use paste . df$x <- paste(df$n,df$s) df # n s b x # 1 2 aa TRUE 2 aa # 2 3 bb FALSE 3 bb # 3 5 cc TRUE 5 cc 回答2: For inserting a separator: df$x <- paste(df$n, "-",

Unique Key constraints for multiple columns in Entity Framework

↘锁芯ラ 提交于 2019-11-26 06:06:57
I'm using Entity Framework 5.0 Code First; public class Entity { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string EntityId { get; set;} public int FirstColumn { get; set;} public int SecondColumn { get; set;} } I want to make the combination between FirstColumn and SecondColumn as unique. Example: Id FirstColumn SecondColumn 1 1 1 = OK 2 2 1 = OK 3 3 3 = OK 5 3 1 = THIS OK 4 3 3 = GRRRRR! HERE ERROR Is there anyway to do that? With Entity Framework 6.1, you can now do this: [Index("IX_FirstAndSecond", 1, IsUnique = true)] public int FirstColumn { get; set; } [Index("IX