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"
#Assuming iris is already loaded as a df called 'iris' and has a proper header
iris = iris[[col for col in iris.columns if 'Length' in col]]
print iris.head()
您可以为此使用^{} 方法(使用
axis=1
过滤列名)。此功能有不同的可能性:相当于
if 'Length' in col
:使用regex(但是,它使用的是},因此您可能需要调整regex):
re.search
,而不是{使用Python的
in
语句,其工作方式如下:或者,使用正则表达式
^{pr2}$第一个会跑得更快,但第二个会更准确。在
相关问题 更多 >
编程相关推荐