Tag: apply

python – pandas create new column based on values from other columns / apply a function of multiple columns, row-wise

The Question : 375 people think this question is useful I want to apply my custom function (it uses an if-else ladder) to these six columns (ERI_Hispanic, ERI_AmerInd_AKNatv, ERI_Asian, ERI_Black_Afr.Amer, ERI_HI_PacIsl, ERI_White) in each row of my dataframe. I’ve tried different methods from other questions but still can’t seem to find the right answer for

Replace loop for apply or sappy?

问题内容: I have a program, but I need to replace loop for apply or sapply? Is this possible in my case? Can you help me? My code TD = stri_read_lines("script.R") chars = data.frame() for(i in 1:length(TD)){ if(TD[i] !='') { char= unlist(strsplit(TD[i], split="")) for ( j in 1:nchar(TD[i]) ) { chars =rbind(chars , data.frame(a=char[j], b=i, c=