3

I have a pyspark dataframe. I was able to convert dynamic dataframe to spark dataframe by persons.toDF(). I want to convert the spark dataframe again back to dynamic dataframe in pyspark.I wanted to cast my column to timestamp and again convert it to dynamic dataframe to resolveChoices. Please help me

2 Answers 2

4

at least you need pyspark.context, awsglue.context and awsglue.dynamicframe There is example :

from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.dynamicframe import DynamicFrame

sc = SparkContext()
glueContext = GlueContext(sc)

NewDynamicFrame = DynamicFrame.fromDF(persons, glueContext, "nested")

"persons" is your DataFrame

Please check following links :

  1. https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-python-samples-medicaid.html

  2. https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-extensions-dynamic-frame.html#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-fromDF

Sign up to request clarification or add additional context in comments.

Comments

3

You can create a dynamic frame from dataframe using the fromDF function.

Basic Syntax

dyf = fromDF(dataframe, glue_ctx, name)

where,

  • dataframe – The Apache Spark SQL DataFrame to convert (required).

  • glue_ctx – The GlueContext Class object that specifies the context for this transform (required).

  • name – The name of the resulting DynamicFrame (required).

Reference : Dynamic frame from dataframe

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.