【发布时间】:2019-08-12 21:26:15
【问题描述】:
给定一个df
session_id article session_type
1 a req
1 b req
1 null action
2 home req
2 h req
2 j req
2 home req
3 home req
3 home req
3 r req
3 home req
我想聚合到一列作为字典: 1.独特的文章 2.独特的会话类型 3.统计所有不连续的家
输出:
sess_id agg_col
1 {unique_articles:2,unique_promotion_session:2,non_consectutive_home:0}
2 {unique_articles:2,unique_promotion_session:1,non_consectutive_home:2}
3 {unique_articles:1,unique_promotion_session:1,non_consectutive_home:1}
谢谢。
【问题讨论】:
-
为什么要这样做?在 python 列中存储字典并没有那么有用。
-
为什么
non_consectutive_home:1}换成session=2? -
@user3483203 - df 应该作为嵌套结构定向到 BigQuery,如果您认为有更好的技术,我很高兴知道
-
@jezrael - 你说得对,我已经更新了
-
@Moti - 你的熊猫版本是什么?
标签: python-3.x pandas pandas-groupby