How to create a pyspark Row using string variable as column name instead of string literal

Viewed 17

I have a pyspark test case needed to create a sample dataframe using the following format

return self.spark.createDataFrame(
            [
                Row(
                    person = "john",
                    age = 16,
                ),
             ]

As can be seen each column name is listed as string literal, but say if I have a column name as a variable COMPANY_UUID_COL = 'uuid' and would like to use COMPANY_UUID_COL instead of directly using this magic value 'uuid', somehow as a new column, without changing the original way of creating the dataframe, how should I be doing it?

0 Answers
Related