【发布时间】:2018-04-26 13:36:14
【问题描述】:
我在 Pandas 中有以下数据框...
+-----------------------+
| | count |
+-----------------------+
| group | |
+-----------------------+
| 11- | 99435 |
+-----------------------+
| Bachelor+ | 64900 |
+-----------------------+
| Just 12 | 162483 |
+-----------------------+
| Some College | 61782 |
+-----------------------+
我想执行以下代码,但出现错误...
death_2013['percent_of_total'] = death_2013.count.apply(
lambda x: (x / death_2013.count.sum()))
我收到以下错误...
AttributeError: 'function' object has no attribute 'apply'
我检查了death_2013.dtypes 和count 是一个int64。我无法弄清楚代码有什么问题。
【问题讨论】:
-
count 是列名。我可以做
death_2013.count.apply或death_2013['count'].apply,但它们似乎都不起作用。奇怪的是,我有这行代码处理不同的数据集。 -
错误信息提示它是一个函数对象
-
为什么不
death_2013['count'].apply()? -
天啊!!!似乎
count是 pandas 或 python 中的保留字。我更改了列名,现在apply()正在工作
标签: python python-3.x pandas dataframe