【问题标题】:Computing Arctan2 with 1 argument in Pandas DataFrame在 Pandas DataFrame 中使用 1 个参数计算 Arctan2
【发布时间】:2022-11-02 21:15:19
【问题描述】:

我有一个 DF,我需要计算两个南北风分量的反正切值。但是,根据文档,arctan2 函数似乎只需要 2 个参数 x,y :

numpy.arctan2(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'arctan2'>

但是,我需要除以 x、y 分量以获得我想要的答案。所以,我需要这样做——

dfout = np.arctan2(x/y) 使用 1 个参数,但文档说我需要 2 个参数 x,y。

我将“/”符号视为一个选项,但我不确定这是否适用或如何做到这一点。有任何想法吗?

我的数据在 df 中如下所示:

day hour    Cns       Cew
1   0       126.002   -100.812
1   1      -42.3775    18.6631
1   2       64.3313   -121.167

我需要在上面的示例中执行此操作:

dfout = np.arctan2(df.Cew/df.Cns)

但我得到这个错误 -

TypeError: arctan2() takes from 2 to 3 positional arguments but 1 were given

我已经尝试过了,但出现语法错误。

dfout = np.arctan2(df.Cew,df.Cns,/)

非常感谢,

【问题讨论】:

    标签: python pandas math trigonometry


    【解决方案1】:

    np.arctan2() 旨在解决其x / y 参数中的符号组合导致的歧义,因此要求两个论点。

    如果您不需要解决这种歧义,您可以安全地使用np.arctan()

    另请参阅Wikipedia's page for atan2,它为您提供了一些更精确的上下文,以了解arctan()arctan2() 之间差异的数学基础。

    【讨论】:

      猜你喜欢
      • 2022-06-17
      • 2017-09-22
      • 2020-12-25
      • 2021-04-02
      • 2013-11-28
      • 2017-12-15
      • 2021-08-05
      • 1970-01-01
      • 2019-08-01
      相关资源
      最近更新 更多