【发布时间】:2022-01-17 19:49:30
【问题描述】:
这是 ohlc 数据帧,我想从中切出 efi 的值。
brick_counts time_id efi
1 nan 1000
2 nan 1500
3 nan 2000
4 2 2500
5 2 2600
6 2 3200
要从这个 ohlc 数据帧中分割单个值,我正在使用这行代码,
ohlc.loc[(ohlc['brick_counts'] == -5) & (ohlc['time_id'] == 2 ), 'efi'].values[0]
这条线工作得很好,给了我价值,但是当我尝试应用这条线来使用 nan 切片值时,
ohlc.loc[(ohlc['brick_counts'] == 5) & (ohlc['time_id'] == float("nan")), 'efi'].values[0]
它显示了这个错误
IndexError: index 0 is out of bounds for axis 0 with size 0
那么我应该如何使用brick_counts 和time_id 列的nan 值作为我的输入来分割efi 的值?
【问题讨论】:
标签: python pandas dataframe key-value numpy-slicing