Python loc + isin returns FutureWarning(元素比较失败)
Python loc + isin returns FutureWarning (elementwise comparison failed)
df = df.loc[df['var'].isin(df2['this'].unique().tolist())]
上面的代码给了我一个 FutureWarning,我想不出解决办法。这是错误还是功能?
C:\Users\Username\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\arraysetops.py:569:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison mask
|= (ar1 == a)
比较数据集中的 "int" 和 "str" 时会出现此警告。将 .astype(str)
添加到您的比较数据集。
试试这个
df = df.loc[df['var'].astype(str).isin(df2['this'].astype(str).unique().tolist())]
df = df.loc[df['var'].isin(df2['this'].unique().tolist())]
上面的代码给了我一个 FutureWarning,我想不出解决办法。这是错误还是功能?
C:\Users\Username\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\arraysetops.py:569: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison mask |= (ar1 == a)
比较数据集中的 "int" 和 "str" 时会出现此警告。将 .astype(str)
添加到您的比较数据集。
试试这个
df = df.loc[df['var'].astype(str).isin(df2['this'].astype(str).unique().tolist())]