【发布时间】:2016-08-05 20:01:40
【问题描述】:
我收到一条警告,我想检查它是否会中断。我在很多情况下都使用这样的 np.where (对我来说,它类似于 excel 中的 if 语句)。有没有更好或更多的pythonic或pandas方式来做到这一点?我试图将一维变成我可以轻松进行数学运算的东西。
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
【问题讨论】:
-
您的
pandas和numpy是什么版本?print pd.show_versions()