333333333333333

#!/usr/bin/env python3
import sys

def read_input(file):
    for line in file:
        yield line.strip().split(',')

def main():
    input = read_input(sys.stdin)
    
    for row in input:
        # Ensure the line has the correct number of parts
        if len(row) != 6:
            continue
        user_id, item_id, behaviour_type, user_geohash, item_category, time = row

        # Remove the user_geohash field
        # Extract hour from the time field (assuming time format is YYYY-MM-DD HH:MM:SS)
        hour = time.split(' ')[1].split(':')[0]

        # Only consider purchase actions (behaviour_type == 4)
        if behaviour_type == '4':
            print(f"{hour}\t{item_category}\t1")

if __name__ == "__main__":
    main()
 

#!/usr/bin/env python3
import sys

def read_input(file):
    for line in file:
        yield line.strip().split('\t')

def main():
    current_hour = None
    current_category = None
    current_count = 0
    input = read_input(sys.stdin)
    
    for hour, item_category, count in input:
        count = int(count)
        
        if current_hour == hour and current_category == item_category:
            current_count += count
        else:
            if current_hour and current_category:
                # Output the results for the current hour and category
                print(f"{current_hour}\t{current_category}\t{current_count}")
            current_hour = hour
            current_category = item_category
            current_count = count
    
    # Output the last hour and category's results
    if current_hour and current_category:
        print(f"{current_hour}\t{current_category}\t{current_count}")

if __name__ == "__main__":
    main()
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值