pyspark.sql.DataFrame.withMetadata

DataFrame.withMetadata(columnName: str, metadata: Dict[str, Any]) → pyspark.sql.dataframe.DataFrame

Returns a new DataFrame by updating an existing column with metadata.

Parameters
columnNamestr

string, name of the existing column to update the metadata.

metadatadict

dict, new metadata to be assigned to df.schema[columnName].metadata

Examples

>>> df_meta = df.withMetadata('age', {'foo': 'bar'})
>>> df_meta.schema['age'].metadata
{'foo': 'bar'}