【发布时间】:2016-09-23 10:52:41
【问题描述】:
经过一些处理后,我得到了一个数据框,其中我在数据框列中有一个字典。现在我想更改列中字典的键。从 "_1" 到 "product_id" 和 "_2" 到 "timestamp"。
这里是处理的代码:
df1 = data.select("user_id","product_id","timestamp_gmt").rdd.map(lambda x: (x[0], (x[1],x[2]))).groupByKey()\
.map(lambda x:(x[0], list(x[1]))).toDF()\
.withColumnRenamed('_1', 'user_id')\
.withColumnRenamed('_2', 'purchase_info')
结果如下:
【问题讨论】:
标签: python dictionary apache-spark dataframe pyspark