This is a header to be ignored
20001001 23.0 5 X 1 Kevin
20001002 23.1 5 Y 1 Kevin
20001003 23.4 5 X 1 Kevin
20001004 23.3 5 Y 1 Steve
20001005 23.4 5 X 1 Steve
我想阅读此文件并调用属于Kevin和/或Steve的数据。像这样的东西: DF ['凯文'] 20001001 23.0 5 X 1 20001002 23.1 5 Y 1 20001003 23.4 5 X 1
答案 0 :(得分:0)
您可以定义多个蒙版并使用它们来过滤您的df:
In [8]:
kev_mask = (df['name'] == 'Kevin')
steve_mask = (df['name'] == 'Steve')
df[kev_mask]
Out[8]:
date col1 col2 col3 col4 name
0 20001001 23.0 5 X 1 Kevin
1 20001002 23.1 5 Y 1 Kevin
2 20001003 23.4 5 X 1 Kevin
In [9]:
df[steve_mask]
Out[9]:
date col1 col2 col3 col4 name
3 20001004 23.3 5 Y 1 Steve
4 20001005 23.4 5 X 1 Steve
In [10]:
df[kev_mask | steve_mask]
Out[10]:
date col1 col2 col3 col4 name
0 20001001 23.0 5 X 1 Kevin
1 20001002 23.1 5 Y 1 Kevin
2 20001003 23.4 5 X 1 Kevin
3 20001004 23.3 5 Y 1 Steve
4 20001005 23.4 5 X 1 Steve