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
Brandon Dyer
  • 1,316
  • 12
  • 21
sygma
  • 41
  • 1
  • 8

2 Answers2

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()
E. Zeytinci
  • 2,642
  • 1
  • 20
  • 37
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"]
Sandeep Fatangare
  • 2,054
  • 9
  • 14