简体   繁体   English

使用列条件过滤熊猫数据框的行,但列的名称应该是部分匹配的

[英]Filter rows of pandas dataframe with column condition, but the name of the column is supposed to be partial match

I have data like this我有这样的数据

在此处输入图像描述

I want to apply column condition to filter out the rows based on the condition WinningPoints > 40 .我想应用列条件来过滤掉基于条件WinningPoints > 40的行。 I can get this done by using dataframe[(dataframe.WinningPoints > '40')]我可以通过使用dataframe[(dataframe.WinningPoints > '40')]来完成这项工作

However, I would like to pass a partial label in the column tag and maybe use regex to match the entire string,something like this但是,我想在列标签中传递一个部分标签,也许使用正则表达式来匹配整个字符串,就像这样

dataframe[(dataframe. WinningPo. * > '40')]数据框[(数据框。WinningPo。 *>'40')]

I want to print all the columns.我想打印所有的列。

How can this be done?如何才能做到这一点? Thanks for your help in advance.提前感谢您的帮助。

After going through the pandas documentation, I didn't find pancea.在浏览了熊猫文档后,我没有找到灵丹妙药。 But, you can use the filter function in pandas to get a subset dataframe like this:但是,您可以使用 pandas 中的过滤器函数来获取一个子集数据框,如下所示:

df.filter(regex='WinningPo.*',axis = 1)

And then apply your condition for each column然后对每一列应用你的条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM