Created
November 12, 2018 03:50
-
-
Save christinebuckler/02e021a285069ce98c01a24ab348ca14 to your computer and use it in GitHub Desktop.
PySpark deep copy dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
X = spark.createDataFrame([[1,2], [3,4]], ['a', 'b']) | |
_schema = copy.deepcopy(X.schema) | |
_X = X.rdd.zipWithIndex().toDF(_schema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This tiny code fragment totally saved me -- I was running up against Spark 2's infamous "self join" defects and stackoverflow kept leading me in the wrong direction. Within 2 minutes of finding this nifty fragment I was unblocked. Much gratitude!