Julia(Julia lang)如何获取数据帧的子集并按组计算不同的活动?
我正在尝试获取数据帧的子集。 起点必须是当月的第一天。 终点必须是当天。 之后,我想按小组统计不同的活动 数据帧:Julia(Julia lang)如何获取数据帧的子集并按组计算不同的活动?,julia,Julia,我正在尝试获取数据帧的子集。 起点必须是当月的第一天。 终点必须是当天。 之后,我想按小组统计不同的活动 数据帧: date | activity 06-07-2020 | walking 06-07-2020 | rucking 07-07-2020 | tennis ... 我试过: DfName[Dates.firstdayofmonth(Dates.today()):Dates.today(), :] combine(groupby(DfName, :act
date | activity
06-07-2020 | walking
06-07-2020 | rucking
07-07-2020 | tennis
...
我试过:
DfName[Dates.firstdayofmonth(Dates.today()):Dates.today(), :]
combine(groupby(DfName, :activity), nrow => :count)
@where(DfName, :date .>= Dates.firstdayofmonth(Dates.today()), :date .<= Dates.today())`
结果:
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Dates.Day
@where(DfName, :date .>= Dates.firstdayofmonth(Dates.today()), :date .<= Dates.today())
ERROR: MethodError: no method matching isless(::Dates.Date, ::String)
Closest candidates are:
isless(::DataValues.DataValue{Union{}}, ::Any) at /home/...
isless(::PyObject, ::Any) at /home/...
我也试过:
DfName[Dates.firstdayofmonth(Dates.today()):Dates.today(), :]
combine(groupby(DfName, :activity), nrow => :count)
@where(DfName, :date .>= Dates.firstdayofmonth(Dates.today()), :date .<= Dates.today())`
结果:
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Dates.Day
@where(DfName, :date .>= Dates.firstdayofmonth(Dates.today()), :date .<= Dates.today())
ERROR: MethodError: no method matching isless(::Dates.Date, ::String)
Closest candidates are:
isless(::DataValues.DataValue{Union{}}, ::Any) at /home/...
isless(::PyObject, ::Any) at /home/...
我如何在Julia中做到这一点?使用以下方法:
filter(:date => x -> Dates.firstdayofmonth(Dates.today()) <= x <= Dates.today(), DfName)
或
或
或即将在DataFrames.jl 1.0版本中发布:
subset(DfName,
:date => ByRow(>=(Dates.firstdayofmonth(Dates.today())),
:date => ByRow(<=(Dates.today())
)
下一次,请花一分钟时间看看如何正确格式化代码、数据和错误消息,在这里为您完成。