Building a row from a dict in pySpark

前端 未结 2 892
小蘑菇
小蘑菇 2021-02-01 03:17

I\'m trying to dynamically build a row in pySpark 1.6.1, then build it into a dataframe. The general idea is to extend the results of describe to include, for exam

2条回答
  •  庸人自扰
    2021-02-01 04:07

    In case the dict is not flatten, you can convert dict to Row recursively.

    def as_row(obj):
        if isinstance(obj, dict):
            dictionary = {k: as_row(v) for k, v in obj.items()}
            return Row(**dictionary)
        elif isinstance(obj, list):
            return [as_row(v) for v in obj]
        else:
            return obj
    

提交回复
热议问题