'Python Polars Read CSV with header names

In pandas, one can specify the names of a csv with:

pd.read_csv(filename, names = [ 'city', 'pop' ])

How does on do so in Python polars?



Solution 1:[1]

You can specify the columns to read using the columns parameter in read_csv. If you want to rename, there is also the parameter new_columns, which accepts a list of column names that you will assign.

See also the reference guide: https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.read_csv.html?highlight=read_csv.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jvz