0

How can I convert my dataframe df to a list of rows?

Code

df = glueContext.create_dynamic_frame_from_options(
    connection_type = "s3",
    connection_options = {"paths": ["s3://data/tmp1/file.csv"]},
    format = "csv",
)
df = df.toDF()
list = df.values.tolist()

Error

dataframe has no attribute values
4
  • Did you try toPandas()? Commented Jan 16, 2020 at 18:48
  • how please. @E.Zeytinci Commented Jan 16, 2020 at 18:52
  • do you mean df = df.toPandas() and then liste = df.values.tolist() ? Commented Jan 16, 2020 at 18:55
  • 1
    Isn't this a duplicate of stackoverflow.com/q/34817549/11301900 ? Commented Jan 16, 2020 at 22:53

2 Answers 2

2

IMHO, you can use toPandas(),

df = glueContext.create_dynamic_frame_from_options(
    connection_type="s3", 
    connection_options={"paths": ["s3://data/tmp1/file.csv"]}, 
    format="csv")

df = df.toPandas()
liste = df.values.tolist()
Sign up to request clarification or add additional context in comments.

Comments

0

In glue, you may use DyanamicFrame.map() method (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-map)

df.map(to_list)
def to_list(rec):
       rec["list"] = [rec["col1"], rec["col2"] ]
       del rec["col1"]
       del rec["col2"]

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.