python Pandas : 'numpy.ndarray' object has no attribute 'apply'

标签 python pandas numpy

我有一个数据框,我从中选择了唯一值,它产生了一个形状为 (1187,) 的 ndarray(“unManager”)...只有一列。

现在,我编写了一个函数来对数据帧的一些行进行分组,进行计算并在 ndarray 中添加值。

我为此在 ndarray ("unManager") 上使用应用程序,但出现以下错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-48-ff7e78ab33a7> in <module>()
----> 1 unManager.apply(runThis, axis=0)

AttributeError: 'numpy.ndarray' object has no attribute 'apply'

现在,当我尝试将 ndarray(“unManager”)转换为数据帧时,通过:

dfs = pd.DataFrame(unManager,index=unManager[0])

我收到以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-3ee3d2605321> in <module>()
----> 1 dfs = pd.DataFrame(unManager,index=unManager[0])
.
.
TypeError: Index(...) must be called with a collection of some kind, 'actama99,CLE' was passed

这里的 'actama99,CLE' 是形状为 (1187,) 的 ndarray ("unManager") 的第一个值。

有人可以告诉我我做错了什么吗?时间差

最佳答案

dfs = pd.DataFrame(unManager,index=unManager[0])

unManager[0] 返回一个标量,它不是一个集合

你想要

dfs = pd.DataFrame(dict(unManagers=unManager))

关于 python Pandas : 'numpy.ndarray' object has no attribute 'apply' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224987/

相关文章:

python - 将 datetime.max 插入 pandas 系列会更改系列类型

python - 绘制按 id 分组的时间序列

python - 协调 basemap 箭袋和 matplotlib 箭头

python - 如何获得由 scipy.cluster.hierarchy 制作的树状图的子树

python - 无法使用 SIGKILL 杀死 docker 容器内的 pid 1

python - Scrapy:将来自不同链接的抓取数据关联到 1 个项目/模型

python - KD/Qtree 实现

python - numpy 逻辑中首次出现

python - 为什么 python 的 eval 有长度限制?

python - 如何从父子目录导入模块