I have big polars dataframe that I want to write into external database (sqlite for example) How can I do it?
In pandas, you have to_sql() function, but I couldn't find any equivalent in polars
I have big polars dataframe that I want to write into external database (sqlite for example) How can I do it?
In pandas, you have to_sql() function, but I couldn't find any equivalent in polars
Polars doesn't provide a utility for inserting data to a database.
Your options, that I can think of, are:
to_pandas().to_sql(...)
DIY
a. Generate insert statements from df.rows()
like this
b. Apparently sqlite doesn't do bulk inserts but for postgres you can use a combination of io
, write_csv
, and copy_from
which will be much faster than using insert statements.
Save parquet files and either use them directly or use something like duckdb to access them as though they were a traditional db