我在python中使用包dfply
,它模仿R中的包dplyr
。
这就是我要运行的简单代码。我已经在我的环境中加载了这个数据集'data',我只想为那个变量分组。在
import dfply as dp
data['CO_SPORTELLO']=data['CO_SPORTELLO'].apply(lambda x: str(x))
data=(data >>
dp.group_by(X.CO_SPORTELLO))
我一直获取的错误是:NameError: name 'X' is not defined
。在
从软件包文档:
^{pr2}$The DataFrame as it is passed through the piping operations is represented by the symbol X. It records the actions you want to take (represented by the Intention class), but does not evaluate them until the appropriate time. Operations on the DataFrame are deferred. Selecting two of the columns, for example, can be done using the symbolic X DataFrame during the piping operations.
您需要
from dfply import *
;这应该定义X
。在或者将代码中的
X
替换为dp.X
。在相关问题 更多 >
编程相关推荐