熊猫数据框查询未找到值

时间:2019-10-05 07:37:28

标签: python pandas dataframe

我有一个问题,我无法理解为什么我搜索的值似乎不存在于数据框中。

我首先在原始数据框中组合了几个数字列,然后分配给一个新列。然后,我从该组合列中提取了一个唯一值列表

~snip

    self.df['Flitch'] = self.df['Blast'].map(
                str) + "-" + self.df['Bench'].map(str)

    self.flitches = self.df['Flitch'].unique()

~snip

现在在代码中稍稍远一点,我需要获取对应于这些唯一标识符的最早的日期值。因此,我在数据框上运行查询:

~snip

def get_dates(self):
        '''Extracts mining and loading dates from filtered dataframe'''

        loading_date, mining_date = [],[]

        #loop through all unique flitch ids and get their mining
        #and loading dates

        for flitch in self.flitches:

            temp = self.df.query('Activity=="MINE"')
            temp = temp.query(f'Flitch=={flitch}')
            mining = temp['PeriodStartDate'].min()
            mining_date.append(mining)   

~snip

...我什么也没得到。我不明白为什么。我的意思是,我正在比较从该列提取的数据与该同一列,但没有任何匹配项。

我走了,手动检查唯一ID列表是否正确填充。

我检查了我正在运行查询的数据帧的确具有相同的波动ID。

我已经手动检查了self.flitches列表中的几个随机值,每次都会以False的形式返回。

在我将这两列组合在一起并且仅使用'Blast'作为标识符之前,一切正常,但是现在我不确定发生了什么。

例如,我在这里打印了self.flitches列表:

['5252-528' '5251-528' '3030-492' '8235-516' '7252-488' '7251-488'
 '2351-588' '5436-588' '1130-624' '5233-468' '1790-516' '6301-552'
 '6302-552' '5444-576' '2377-564' '2380-552' '2375-564' '5253-528'
 '2040-468' '2378-564' '1132-624' '1131-624' '6314-540' '7254-488'
 '7253-488' '8141-480' '7250-488']

这是self.df['Flitch']列中的数据:

173     5252-528
174     5251-528
175     5251-528
176     5251-528
177     5251-528
178     5251-528
180     3030-492
181     3030-492
182     3030-492
183     3030-492
...

看起来他们必须匹配,但他们不需要...

0 个答案:

没有答案