个人备案放企业网站,wordpress 自动加载下一页,罗田做网站,怎么申请个人网站pandas版本1.5.3中groupby方法#xff0c;当设置group_keysTrue时#xff0c;会以groupby的字段为第一级索引#xff0c;如下述代码中time_id作为第一级索引#xff0c;同时保留了原dataframe#xff08;df#xff09;中的索引作为第二级索引。 df.groupby…pandas版本1.5.3中groupby方法当设置group_keysTrue时会以groupby的字段为第一级索引如下述代码中time_id作为第一级索引同时保留了原dataframedf中的索引作为第二级索引。 df.groupby([time_id], group_keysTrue)[wap].apply(log_return)
time_id
0 0 NaN1 0.0000002 0.0000003 0.0000004 0.000000...
26454 5237975 -0.0012285237976 0.0004915237977 -0.0050315237978 0.0032195237979 0.003264
Name: wap, Length: 5237980, dtype: float64group_keys的意思就是是否保留groupby的feature如time_id作为keys放入结果中True是放False是不放。这也印证了帮助里的说明 group_keys : bool, optional When calling apply and the by argument produces a like-indexed (i.e. :ref:a transform groupby.transform) result, add group keys to index to identify pieces. By default group keys are not included when the result’s index (and column) labels match the inputs, and are included otherwise. This argument has no effect if the result produced is not like-indexed with respect to the input. 因此当设置group_keysFalse时group keys(time_id)就不在返回结果中了如下所示。在设置为False是可以直接将返回结果作为原dataframe(df)的一列很方便。 df.groupby([time_id], group_keysFalse)[wap].apply(log_return)
0 NaN
1 0.000000
2 0.000000
3 0.000000
4 0.000000...
5237975 -0.001228
5237976 0.000491
5237977 -0.005031
5237978 0.003219
5237979 0.003264
Name: wap, Length: 5237980, dtype: float64PS:对英文帮助的深入理解需要结合实际应用。