有没有办法使用文本匹配或正则表达式选择列的子集?
在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"
Run Code Online (Sandbox Code Playgroud)
您可以filter为此使用方法(用于axis=1过滤列名)。此功能具有不同的可能性:
等效于if 'Length' in col:
df.filter(like='Length', axis=1)
Run Code Online (Sandbox Code Playgroud)使用正则表达式(但是,它使用re.search而不是re.match,因此您可能需要调整正则表达式):
df.filter(regex=r'\.Length$', axis=1)
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
2234 次 |
| 最近记录: |