If your dataframe is with following schema
root |-- _1: struct (nullable = true) | |-- key: string (nullable = true) |-- _2: struct (nullable = true) | |-- value: long (nullable = true)
Then you can use * to select all elements of struct columns into separate columns and then use struct inbuilt function to combine them back to one struct field
from pyspark.sql import functions as F df.select(F.struct("_1.*", "_2.*").alias("_1"))
you should get your desired output dataframe
root |-- _1: struct (nullable = false) | |-- key: string (nullable = true) | |-- value: long (nullable = true)
Updated
More generalized form of above code if all the columns in original dataframe are struct is as below
df.select(F.struct(["{}.*".format(x) for x in df.columns]).alias("_1"))