【问题标题】:How to fix deprecation warning for using non-tuple sequence for multidimensional indexing如何修复使用非元组序列进行多维索引的弃用警告
【发布时间】:2019-02-07 09:17:39
【问题描述】:

请原谅我的菜鸟问题,但我有点困惑为什么会出现这个警告以及我能做些什么来解决它。

我尝试用df[tuple('Air Temp')] 替换df['Air Temp'],但它只会引发更多错误。

代码:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("./data/elnino.csv")

df.columns = [col.strip() for col in df.columns]

df['Air Temp'] = pd.to_numeric(df['Air Temp'], errors = 'coerce')
df['Sea Surface Temp'] = pd.to_numeric(df['Sea Surface Temp'], 
errors = 'coerce')

错误:

stats.py:1713: FutureWarning: 使用非元组序列 不推荐使用多维索引;使用 `arr[tuple(seq)]` 而不是 `arr[seq]`。在未来,这将被解释为 数组索引,`arr[np.array(seq)]`,这将导致 错误或不同的结果。
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

【问题讨论】:

  • 你确定要使用元组吗?请看这个输出: tuple('Air Temp') Out[42]: ('A', 'i', 'r', ' ', 'T', 'e', 'm', 'p'
  • Some googling 建议您在某些时候使用scipy.stats。请问你能显示这样做的代码吗?
  • 它看起来好像是 SciPy 中的一个小错误,已修复 here。所以你基本上可以忽略它:当你更新到 SciPy 的下一个版本时(当它可用时),警告应该会消失。

标签: python pandas scipy


【解决方案1】:

我遇到了同样的问题,这样做为我解决了这个问题: 在命令行中运行以下命令:

pip install --upgrade scipy

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 2021-05-29
    • 2019-03-06
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    相关资源
    最近更新 更多