我从 CSV 文件中获取这些数据,我需要将此数据发送到服务器。但我只需要这个列表中的价值。{1: Row(Moid=1, Tripid='1', Tstart='2007-05-27', Tend='2007-05-27 08:36:47.846', Xstart='12785', Ystart='1308', Xend='12785', Yend='1308'), 2: Row(Moid=2, Tripid='10', Tstart='2007-05-27', Tend='2007-05-28 08:52:53.673', Xstart='9716', Ystart='-55', Xend='9716', Yend='-55')}我想得到这个{ (1, 1, 2007-05-27, 2007-05-2708:36:47.846 , 12785, 1308, 12785, 1308) (2, 10, 2007-05-27, 2007-05-2808:52:53.673 , 9716, -55, 9716, -55)
1 回答
浮云间
TA贡献1829条经验 获得超4个赞
您可以使用 rdd 和将行转换为元组的映射函数。我只是将您的前 3 个值用于示例实现:
df = spark.createDataFrame([(1,"1",'2007-05-27'),(2,"10", "2007-05-27")], ['moid',"tripid","tstart"])
print df.rdd.map(lambda r: tuple(r)).collect()
输出将是一个元组列表:
[(1, u'1', u'2007-05-27'), (2, u'10', u'2007-05-27')]
添加回答
举报
0/150
提交
取消