I want to create a new polars dataframe from numpy arrays, so I want to add the column-names when creating the dataframe (as I do with pandas).
df = pl.DataFrame(noisy_data.tolist(), columns=[f"property_{i}" for i in range(num_columns)])
But polars does not like "columns"
TypeError: DataFrame.__init__() got an unexpected keyword argument 'columns'
In the Polats dataframe documentation I cannot see any parameter for defining the columns names
class polars.DataFrame(
data: FrameInitTypes | None = None,
schema: SchemaDefinition | None = None,
*,
schema_overrides: SchemaDict | None = None,
strict: bool = True,
orient: Orientation | None = None,
infer_schema_length: int | None = 100,
nan_to_null: bool = False,
)
Another option is to rename the columns with a list of names after df creation.
You should use
schema, notcolumnsas parameter to set up the column names inDataFrame:As described in the documentation: