FutureWarning:元素比较失败;而是返回标量 [英] FutureWarning: elementwise comparison failed; returning scalar instead

查看:148
本文介绍了FutureWarning:元素比较失败;而是返回标量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到警告,我想检查这是否会中断.我在很多情况下都像这样使用 np.where (对我来说,它类似于 excel 中的 if 语句).有没有更好或更多的pythonic或pandas方法来做到这一点?我试图将一维变成我可以轻松进行数学运算的东西.

I am receiving a warning and I want to check if this will break. I am using np.where like this in a lot of cases (it is similar, for me, to an if statement in excel). Is there a better or more pythonic or pandas way to do this? I'm trying to turn one dimension into something I can easily do mathematical operations on.

df['closed_item'] = np.where(df['result']=='Action Taken', 1, 0)

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  result = getattr(x, name)(y)


INSTALLED VERSIONS
------------------
python: 3.5.1.final.0
python-bits: 64
OS: Windows
OS-release: 10

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.0
setuptools: 20.2.2
Cython: 0.23.4
numpy: 1.11.0
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.5.1
matplotlib: 1.5.1
openpyxl: 2.2.6
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0

推荐答案

比较数据集中的int"和str"时会出现此警告.将 .astype(int) 添加到您的比较数据集.试试:

This warning occurs when comparing "int" and "str" in your dataset. Add .astype(int) to your comparison dataset. Try:

df['closed_item'] = np.where(df['result'].astype(str)=='Action Taken', 1, 0)

这篇关于FutureWarning:元素比较失败;而是返回标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆