Skip to main content
`Ctrl`+`K`

# smallpond.dataframe.DataFrame.flat_map

DataFrame.flat_map(sql_or_func: str | Callable[[Dict[str, Any]], List[Dict[str, Any]]], *, schema: Schema | None = None, **kwargs) → DataFrame

  Apply a function to each row and flatten the result.

  ## Parameters

  sql_or_func

    A SQL expression or a function to apply to each row. For functions, it should take a dictionary of columns as input and returns a list of dictionaries. SQL expression is preferred as it’s more efficient.

  schema, optional

    The schema of the output DataFrame. If not passed, will be inferred from the first row of the mapping values.

  ## Examples

      df = df.flat_map('unnest(array[a, b]) as c')
      df = df.flat_map(lambda row: [{'c': row['a']}, {'c': row['b']}])