简体   繁体   English

如何使用pyspark将没有标题的行从数据框中获取到列表中

[英]How to get line without header from dataframe into list with pyspark

I get this data from CSV file and i need to send this data to Server. 我从CSV文件中获取此数据,我需要将此数据发送到服务器。 But i need just value from this list. 但是我只需要这个列表中的值。

{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')}

i want to get this 我想得到这个

{ (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)

You can use rdd and a map function that converts the row to a tuple. 您可以使用rdd和一个将行转换为元组的map函数。 I just used your first 3 values for an example implementation: 我只是将前三个值用于示例实现:

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()

Output would be a list of tuples: 输出将是一个元组列表:

[(1, u'1', u'2007-05-27'), (2, u'10', u'2007-05-27')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python write pyspark dataframe to json without header - python write pyspark dataframe to json without header 如何从 Pyspark 中的 DataFrame 中获取这种子集? - How to get this kind of subset from a DataFrame in Pyspark? 如何使用 Pyspark 中映射表中的值重命名 DataFrame 标头 - How to rename DataFrame header with values from mapping table in Pyspark 从没有标题的数据框中获取列表-pandas python - Get list from dataframe with no header - pandas python Pyspark Dataframe从具有字符串作为元素列表的列中获取唯一元素 - Pyspark Dataframe get unique elements from column with string as list of elements 在 PySpark 中 - 如果列表中的值位于不同的 DataFrame 的行中,如何在 PySpark 中创建新的 DataFrame? - In PySpark - How to create a new DataFrame in PySpark if values from list are in row of a different DataFrame? 如何从 pyspark dataframe 列中的列表中删除特定字符串 - How to remove specific strings from a list in pyspark dataframe column pyspark-如何添加列以从列表中激发 dataframe - pyspark- how to add a column to spark dataframe from a list 如何从其他 pys [park 数据框在 pyspark 上制作列列表 - How to make columns list on pyspark from a other pys[park dataframe 如何从列表列中创建组合的 Pyspark Dataframe - How to create a Pyspark Dataframe of combinations from list column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM