How to slice a pyspark dataframe in two row-wise

后端 未结 5 581
走了就别回头了
走了就别回头了 2020-12-09 18:58

I am working in Databricks.

I have a dataframe which contains 500 rows, I would like to create two dataframes on containing 100 rows and the other containing the rem

5条回答
  •  没有蜡笔的小新
    2020-12-09 19:38

    Try by this way :

    df1_list = df.collect()[:99] #this will return list    
    df1 = spark.createDataFrame(df1) #convert it to spark dataframe
    

    similarly for this as well:

    df2_list = df.collect()[100:499]
    df2 = spark.createDataFrame(df2)
    

提交回复
热议问题