我有两个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
中与LocationCode
匹配的相同的StationCode
列的值。在
例如,dataframe2
中标记为80的行有LocationCode
A13和Min
4。在dataframe1中,StationCode
A13有RailTime
4,因此该行应该从dataframe2
中包含ex。在
相反,在dataframe2
中标记为35的行具有LocationCode
A14和Min
值1,这小于dataframe1
中A14的RailTime
值,因此它应该包含在中。在
简单的解决方案是:
相关问题 更多 >
编程相关推荐