While reading a csv file in pandas, we have option of dtype in read_csv(). Do we have similar option in polars?
import pandas as pd
import polars as pl
data_pd = pd.read_csv('file.csv',dtype={'col1':str, 'col2':str})
data_pl = pl.read_csv('file.csv',dtype={'col1':str, 'col2':str})
I get the following Polars error:
TypeError: read_csv() got an unexpected keyword argument 'dtype'
The right way of choosing the data types when reading a CSV is using schema_overrides
Here is an example of how to use it:
df = pl.read_csv('file.csv', schema_overrides=[pl.String, pl.String])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With