Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何按字段重新划分pySpark RDD,而不将其转换为数据帧?_List_Apache Spark_Dictionary_Rdd - Fatal编程技术网

List 如何按字段重新划分pySpark RDD,而不将其转换为数据帧?

List 如何按字段重新划分pySpark RDD,而不将其转换为数据帧?,list,apache-spark,dictionary,rdd,List,Apache Spark,Dictionary,Rdd,是否可以按特定字段重新划分rdd,而不将其转换为数据帧 我想按第四个字段重新分区 最好在将列表转换为rdd之后 people = [ ('john', 35, 54, 'A'), ('george', 94, 84, 'B'), ('nicolas', 7, 9, 'B'), ('tom', 86, 93, 'A'), ('jason', 62, 73, 'B'), ('bil

是否可以按特定字段重新划分rdd,而不将其转换为数据帧

我想按第四个字段重新分区

最好在将列表转换为rdd之后

people = [
          ('john', 35, 54, 'A'),
          ('george', 94, 84, 'B'),
          ('nicolas', 7, 9, 'B'),
          ('tom', 86, 93, 'A'),
          ('jason', 62, 73, 'B'),
          ('bill', 15, 58, 'A'),
          ('william', 9, 3, 'A'),
          ('brad', 73, 37, 'B'),
          ('cosmo', 52, 67, 'B'),
          ('jerry', 73, 30, 'A')
  ]


rdd = spark.sparkContext.parallelize(people)
或者,在执行dict压缩之后

people = [('john', 35, 54, 'A'),
          ('george', 94, 84, 'B'),
          ('nicolas', 7, 9, 'B'),
          ('tom', 86, 93, 'A'),
          ('jason', 62, 73, 'B'),
          ('bill', 15, 58, 'A'),
          ('william', 9, 3, 'A'),
          ('brad', 73, 37, 'B'),
          ('cosmo', 52, 67, 'B'),
          ('jerry', 73, 30, 'A')]

fields = ('name', 'x', 'y', 'class')

data = [dict(zip(fields, person)) for person in people]

rdd = spark.sparkContext.parallelize(data)

>>> data

[{'name': 'john', 'x': 35, 'y': 54, 'class': 'A'},
 {'name': 'george', 'x': 94, 'y': 84, 'class': 'B'},
 {'name': 'nicolas', 'x': 7, 'y': 9, 'class': 'B'},
 {'name': 'tom', 'x': 86, 'y': 93, 'class': 'A'},
 {'name': 'jason', 'x': 62, 'y': 73, 'class': 'B'},
 {'name': 'bill', 'x': 15, 'y': 58, 'class': 'A'},
 {'name': 'william', 'x': 9, 'y': 3, 'class': 'A'},
 {'name': 'brad', 'x': 73, 'y': 37, 'class': 'B'},
 {'name': 'cosmo', 'x': 52, 'y': 67, 'class': 'B'},
 {'name': 'jerry', 'x': 73, 'y': 30, 'class': 'A'}]
这样做的原因是,在重新分区之后,我将在此数据集上执行嵌套循环,这在列表上执行比在数据帧上执行更容易、更快

如果这是不可能的,我还能做什么?我可以将列表转换为数据帧、重新分区,然后再次将数据帧转换为列表吗