, ,

Convert CSV to Excel with DuckDB, Polars, etc.

Every so often, I have to convert some .txt or .csv file over to Excel format … just because that’s how the business wants to consume or share the data. It is what it is. This means I am often on the lookup for some easy to use, simple, one-liners that I can use to do just that.

Converting a CSV or another kind of file into Excel is just one of those non-value-added tasks that need to take up as little code and space as possible.

Many times if I’m working in some sort of DataFrame centric framework … some variant of the following code will do the trick.

I mean we all hate to use Pandas, but a simple .toPandas().to_excel() is hard to beat.

I’ve also been curious about DuckDB … can we convert CSV files to Excel with a few lines of code with DuckDB, or will it require more than we bargain for?

I mean I wouldn’t exactly call that a one-liner would you? I suppose we could wrap the whole thing into a method that takes some arguments, but seems overkill a little bit. Can we get more of a one-liner with Polars?

I mean we could always just do it with straight up Pandas.