text = ['a,b', 'c,d']
text = ','.join(text)
text = text.split(',')
print(text)
# ['a', 'b', 'c', 'd']
如果所有的单元格都没有写任何内容,如何检查text1,text2,text3列?
预期输出示例
// Page_Load is just an example event here, change to any event you need
protected void Page_Load(object sender, EventArgs e)
{
DetailsView dv = sender as DetailsView;
//using linq to get the CheckBoxField control
var field = dv.Fields.Cast<DataControlField>().Single(x => x.HeaderText == "TitleOfCheckboxField") as CheckBoxField;
}
答案 0 :(得分:3)
我们可以使用rowSums
df[rowSums(df == '') < 2, ]
答案 1 :(得分:2)
您可以这样做:
cols <- paste0("text", 1:3)
df[rowSums(df[cols] == "") < length(cols), ]
答案 2 :(得分:2)
这是使用nchar
+ rowSums
subset(df,rowSums(nchar(as.matrix(df[-1])))>0)
这样
id text1 text2 text3
1 1 sth more final
2 2 another and
3 3 another add where
答案 3 :(得分:2)
使用dplyr
的建议解决方案:
df <- data.frame(id = c(1,2,3,4),
text1 = c("sth","","another",""),
text2 = c("more","another","add",""),
text3 = c("final","and","where",""),
stringsAsFactors = FALSE)
library(dplyr)
df %>%
filter_at(vars(starts_with("text")), any_vars(!. %in% c("")))
返回:
id text1 text2 text3
1 1 sth more final
2 2 another and
3 3 another add where