Dataframe.toPandas始终在驱动程序节点上还是在工作节点上? [英] is Dataframe.toPandas always on driver node or on worker nodes?

查看:237
本文介绍了Dataframe.toPandas始终在驱动程序节点上还是在工作节点上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您正在通过SparkContext和Hive加载大型数据集。所以这个数据集然后分布在你的Spark集群中。例如,对数千个变量进行观察(值+时间戳)。

现在您将使用一些map / reduce方法或聚合来组织/分析数据。例如按变量名分组。

分组后,您可以将每个变量的所有观察值(值)作为时间序列数据框。如果您现在使用DataFrame.toPandas

  def myFunction(data_frame):
data_frame.toPandas()

df = sc.load ....
df.groupBy('var_name')。mapValues(_。toDF).map(myFunction)

$ b $ ol
  • 在每个
    工作节点上转换为Pandas Dataframe(每个变量),或者
  • 是Pandas Dataframes始终在驱动程序节点上,因此数据从工作节点传输到驱动程序?


    解决方案

    在这种情况下,Pandas DataFrame 没有什么特别的。


    • 如果在 pyspark.sql上使用 toPandas 方法创建 DataFrame .dataframe.DataFrame 收集数据并在驱动程序中创建本地Python对象
    • >
    • 如果在执行程序进程中创建 pandas.core.frame.DataFrame 例如在 mapPartitions 中),您只需获得 RDD [pandas .core.frame.DataFrame] 。 Pandas对象之间没有区别,我们假设一个元组

    • 最后在你的示例中伪代码无法工作,因为你无法创建(以合理的方式)执行程序线程内的Spark DataFrame (我假定您的意思是 _。toDF )。


    Imagine you are loading a large dataset by the SparkContext and Hive. So this dataset is then distributed in your Spark cluster. For instance a observations (values + timestamps) for thousands of variables.

    Now you would use some map/reduce methods or aggregations to organize/analyze your data. For instance grouping by variable name.

    Once grouped, you could get all observations (values) for each variable as a timeseries Dataframe. If you now use DataFrame.toPandas

    def myFunction(data_frame):
       data_frame.toPandas()
    
    df = sc.load....
    df.groupBy('var_name').mapValues(_.toDF).map(myFunction)
    

    1. is this converted to a Pandas Dataframe (per Variable) on each worker node, or
    2. are Pandas Dataframes always on the driver node and the data is therefore transferred from the worker nodes to the driver?

    解决方案

    There is nothing special about Pandas DataFrame in this context.

    • If DataFrame is created by using toPandas method on pyspark.sql.dataframe.DataFrame this collects data and creates local Python object on the driver.
    • If pandas.core.frame.DataFrame is created inside executor process (for example in mapPartitions) you simply get RDD[pandas.core.frame.DataFrame]. There is no distinction between Pandas objects and let's say a tuple.
    • Finally pseudocode in you example couldn't work becasue you cannot create (in a sensible way) Spark DataFrame (I assume this what you mean by _.toDF) inside executor thread.

    这篇关于Dataframe.toPandas始终在驱动程序节点上还是在工作节点上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆