我有一个数据集,我正在使用熊猫来拉取。它看起来是这样的:
import pandas as pd
dataset=pd.read_csv('D:\\filename.csv', header=None, usecols=3,4,10,16,22,28])
time=dataset.iloc[:,0]
现在,'time
‘数据集在列中的某个位置有一个值0.00017,我想要找到该位置的索引号。我怎么才能做到这一点?
发布于 2018-06-02 15:47:38
假设你正在处理浮点数,你不能在这里使用相等的比较(因为浮点数的不精确度正在悄悄地出现)。
使用np.isclose
+ np.argmax
idx = np.isclose(df['time'], 0.00017).argmax()
如果此值可能不存在:
m = np.isclose(df['time'], 0.00017)
if m.sum() > 0:
idx = m.argmax()
否则,将idx
设置为任意值(None
、-1
等)。
https://stackoverflow.com/questions/50654661
复制相似问题