Python 3.x 如何使用Pandas从csv筛选特定的行值集?

Python 3.x 如何使用Pandas从csv筛选特定的行值集?,python-3.x,pandas,Python 3.x,Pandas,我有以下csv,我需要过滤特定的行集 table entity_name node_name src_name table_col_name look_up_indicator type keys gw_policy account ns0 fullname insured_name N attribute NA gw_policy polocy ns1 agent_na

我有以下csv,我需要过滤特定的行集

table   entity_name node_name   src_name    table_col_name  look_up_indicator   type       keys
gw_policy   account ns0         fullname    insured_name       N                attribute   NA
gw_policy   polocy  ns1         agent_name  insured_id             N                attribute   NA
gw_policy   account ns2         phone_num   agent_phone        N                attribute   NA
gw_policy   account ns0         fullname    insured_name       N                attribute   NA
gw_policy   polocy  ns1         agent_name  agent              N                attribute   NA
gw_policy   account ns2         phone_num   a_phone            N                attribute   NA
gw_policy   account ns0         fullname    agen_name      N                attribute   NA
gw_policy   polocy  ns1         agent_name  agent              N                attribute   N

现在,从上面的csv中,我需要根据行名称的范围获得一组行

也就是说,在这种情况下,我需要从列名称“table\u col\u name”中获取两个“insured\u name”和两个“agent”之间的行

所以结果看起来像

#期望

那么,如何利用熊猫实现这一目标呢

谢谢你的帮助

谢谢

配合使用:


有3行带有
代理
。如何决定从这两个代理中挑选哪两个?嗨@MayankPorwal。。对不起,我已经更新了sheet@Cloud_Hari请向上投票并通过单击我的答案旁边的勾选接受答案(如果有效)。
# For the insured_name

insured_name
insured_id
agent_phone
insured_name

# For the agent
agent
a_phone
agen_name
agent
In [2278]: insured_name_ix = df[df.table_col_name.eq('insured_name')].index

In [2283]: x = df.loc[insured_name_ix[0]: insured_name_ix[1]]

In [2284]: x
Out[2284]: 
       table entity_name node_name    src_name table_col_name look_up_indicator       type keys
0  gw_policy     account       ns0    fullname   insured_name                 N  attribute  NaN
1  gw_policy      polocy       ns1  agent_name          agent                 N  attribute  NaN
2  gw_policy     account       ns2   phone_num    agent_phone                 N  attribute  NaN
3  gw_policy     account       ns0    fullname   insured_name                 N  attribute  NaN

In [2317]: agent_ix = df[df.table_col_name.eq('agent')].index
In [2319]: y = df.loc[agent_ix[0]: agent_ix[1]]

In [2320]: y
Out[2320]: 
       table entity_name node_name    src_name table_col_name look_up_indicator       type keys
4  gw_policy      polocy       ns1  agent_name          agent                 N  attribute  NaN
5  gw_policy     account       ns2   phone_num        a_phone                 N  attribute  NaN
6  gw_policy     account       ns0    fullname      agen_name                 N  attribute  NaN
7  gw_policy      polocy       ns1  agent_name          agent                 N  attribute    N