【发布时间】:2020-04-24 15:23:42
【问题描述】:
isin() 给了我奇怪的结果。我创建了以下 DataFrame:
import pandas as pd
import numpy as np
test=pd.DataFrame({'1': np.linspace(0.0, 1.0, 11)})
>>> test['1']
0 0.0
1 0.1
2 0.2
3 0.3
4 0.4
5 0.5
6 0.6
7 0.7
8 0.8
9 0.9
10 1.0
Name: 1, dtype: float64
使用(显然)相同的数组 isin() 现在给了我一些奇怪的东西。
>>> test['1'].isin([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])
0 True
1 True
2 True
3 False
4 True
5 True
6 False
7 False
8 True
9 True
10 True
Name: 1, dtype: bool
我怀疑存在一些数值问题或与数据类型有关的问题。有人可以解释一下并告诉我如何预防吗?
【问题讨论】:
标签: python pandas casting rounding-error isin