3
我有两个DataFrames
具有不同数量的行和列,但其中至少有一列包含一些公用信息。具体来说,StationCode
始终是一个LocationCode
:根据另一个数据框的标准选择行
dataframe1.head()
DistanceToPrev LineCode SeqNum StationCode StationName RailTime
0 0 RD 1 A15 Shady Grove 0
1 14151 RD 2 A14 Rockville 4
2 10586 RD 3 A13 Twinbrook 3
3 5895 RD 4 A12 White Flint 3
4 7309 RD 5 A11 Grosvenor-Strathmore 3
5 11821 RD 6 A10 Medical Center 3
6 5530 RD 7 A09 Bethesda 2
7 9095 RD 8 A08 Friendship Heights 3
8 4135 RD 9 A07 Tenleytown-AU 2
9 5841 RD 10 A06 Van Ness-UDC 2
dataframe2.head()
Car Destination DestinationCode DestinationName Group Line LocationCode LocationName Min
0 8 Glenmont B11 Glenmont 1 RD A01 Metro Center BRD
28 8 Glenmont B11 Glenmont 1 RD B01 Gallery Pl-Chinatown ARR
35 6 Glenmont B11 Glenmont 1 RD A14 Rockville 1
45 8 Glenmont B11 Glenmont 1 RD B02 Judiciary Square 2
62 6 Glenmont B11 Glenmont 1 RD B07 Takoma 3
80 6 Glenmont B11 Glenmont 1 RD A13 Twinbrook 4
82 8 Glenmont B11 Glenmont 1 RD B03 Union Station 4
95 6 Glenmont B11 Glenmont 1 RD B08 Silver Spring 5
114 8 Glenmont B11 Glenmont 1 RD B35 NoMa-Gallaudet 6
129 6 Glenmont B11 Glenmont 1 RD A12 White Flint 7
143 8 Glenmont B11 Glenmont 1 RD B04 Rhode Island Ave-Brentwood 8
我想只有在dataframe2
其Min
列都有一个值dataframe1
小于RailTime
列的相同StationCode
相匹配的LocationCode
行。
例如行中dataframe2
标记80具有LocationCode
A13和Min
4.在dataframe1 StationCode
A13具有RailTime
4,使得行应该前从dataframe2
cluded。
相反,在dataframe2
标记35的行具有LocationCode
A14和Min
值1,其小于用于从A14的dataframe1
值RailTime
,所以它应该是在 cluded 。
简单而有效,斯特凡。它完美的作品。我会投票,但还没有足够的代表。公认。 – Keith
不客气,很高兴帮助。 – Stefan