python - IPython 中的 log(dataframe) 与执行中的 log(dataframe) 之间的区别

标签 python python-2.7 pandas dataframe runtime-error

我有一个 pandas 数据框作为 Python 2.7 中的一个属性,称为 probs。如果我尝试执行

log(self.prob['AAA'])

(其中 AAA 是数据框中某一列的有效名称),我收到错误

exceptions.TypeError occurred
Message: only length-1 arrays can be converted to Python scalars

但在交互式 IPython 中,使用相同的值填充 df 并执行

log(df0['AAA'])

准确生成所需的内容(数据框列,每个值都是原始数据的 log())。

差异的原因是什么?有没有办法在正则脚本中获取 IPython 行为?

最佳答案

当 IPython 使用 -pylab 参数启动时,它默认加载 numpy.log 和其他 numpy 函数。
您的脚本中可能没有使用 numpy.log,但可能使用 math.log,因此失败

关于python - IPython 中的 log(dataframe) 与执行中的 log(dataframe) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053801/

相关文章:

python - 如何在 Python 中使用 numpy 获取累计最大索引?

python - Django 静态设置

python - 如何在 Python 中融化或取消堆叠数据帧?

django - 在 django 模板中显示 django-pandas 数据框

python - 我怎样才能捕捉到 pandas DataError?

python - 在 Python 中将分层 pandas DatetimeIndex 保存到 hdf5 时丢失时区感知

python - 如何在Python中依次播放音频文件的序列?

python - tf.data.数据集 : How do I assign shape to a dataset (with shape undefined) that is guaranteed to output certain shape?

python - 当有很多线程时,队列不会处理所有元素

macos - 在 MacOS 中安装 gcutil 时收到错误