1
有没有办法使用文本匹配或正则表达式来选择列的子集?在Pandas中按名称标识多列
在该R这将是这样的:
attach(iris) #Load the 'Stairway to Heaven' of R's built-in data sets
iris[grep(names(iris),pattern="Length")] #Prints only columns containing the word "Length"
很好的信息@joris。但是我也需要获取包含一些其他字符以及列名的列名。例如“Length_1”,“Length_2”,“Width_1”,“Width_2”等是我的列名。我的过滤器函数就像df.filter(like = col +'_',axis = 1),其中col将具有像“Length”,“Width”等等的值,这不是取值。任何想法我应该改正什么? – JKC
你应该可以用正则表达式来做到这一点,例如'regex = r“Length | Width”' – joris