What's a good library for excel to csv file conversion?
Posted by zubb999@reddit | Python | View on Reddit | 21 comments
I'm looking for a Python library that can do the following:
* Convert both XLSX and XLS files to CSV
* Can have some configurations with regards to customizing the delimiter (like | as opposed to ,)
* Can have configurations with regards to multiple tabs/sheets in the excel file (can combine all tabs into a single csv file or make each tab into a separate csv file)
And have backwards functionality
* Can convert CSV to XLSX or XLS
* Can have configurations with regards to using a custom delimiter
* Can have configurations with regards to combining multiple csv files into a single XLSX file (combine multiple csv's into a single excel tab or a separate excel tab for each csv file)
I'm sure there's a library that exists out there, I just wonder if someone could point me in the right direction as a starting point.
Beginning-Fruit-1397@reddit
Polarsss. Ppl should atop recommending pandas in 2026
sinceJune4@reddit
Does it matter if the data is small enough to fit in Excel? I have a lot of legacy code using Pandas…
Beginning-Fruit-1397@reddit
90% of the time I don't even neeed nor care about the speed since like you data is small enough. It's just that the syntax, having an expressions system, etc... is so so much nicer
sinceJune4@reddit
Okay, that’s intriguing. Thanks!
cocojackson@reddit
100 percent. I am not sure why people are so set on using a legacy library at this point.
Mondoke@reddit
I'd just go with Pandas. Read the documentation on pd.read_excel.
If you have really big files to process, you can try openpyxl and python's own csv module.
Empanatacion@reddit
dmertl@reddit
doing people's homework for them, smh. jk.
I keep telling our office we only accept CSV files even though it might be this easy. I don't want to deal with whatever edge cases this might involve.
Empanatacion@reddit
I pasted their post into ChatGPT and pasted one of the examples it gave back in.
😝
Folks round here get cranky if you say, "Have you asked an AI?"
sinceJune4@reddit
Yes, I do
Icy_Peanut_7426@reddit
Fastexel
cocojackson@reddit
Using Polars:
- https://docs.pola.rs/api/python/stable/reference/api/polars.read_excel.html#polars.read_excel
- https://docs.pola.rs/api/python/stable/reference/api/polars.DataFrame.write_csv.html
The engine used to use xlsx2csv directly:
- https://github.com/dilshod/xlsx2csv
If you are using this engine you should probably just use xlsx2csv directly.
I assume polars uses calamine now directly in rust, but you can also look into https://github.com/dimastbk/python-calamine
commandlineluser@reddit
The names are confusing, but Polars uses the
fastexcelpython package.fastexcelis also a wrapper around thecalamineRust package, butpython-calamineis different. (I believe pandas uses that)sylfy@reddit
Polars with calamine if you want the best performance.
commandlineluser@reddit
The names are confusing, but Polars uses the
fastexcelpython package.fastexcelis also a wrapper around thecalamineRust package, butpython-calamineis different. (I believe pandas uses that)swift-sentinel@reddit
Use claude or chatgpt.
scheming_slug@reddit
If you’re working with data that’s in CSV and can fit in Excel, you probably don’t need to worry too much about the speed of Pandas vs a specialized tool. If you mean fastest to set up rather than speed of code execution, pandas is also pretty fast to get started with, especially if you’re just trying to convert back and forth and not do a lot of transformations in between. It would be as simple as:
import pandas as pd
df = pd.read_csv(filename.csv) df.to_excel(filename.xlsx, index=False)
The index=false is just to make sure you don’t put the dataframe index into the exported file. Depending on what your data looks like, you may also want to specify using only a string data type for everything you read in. If you have a column of numeric codes that should be treated as strings, pandas may read them in as a numeric type if you don’t specify.
Quixote1492@reddit
Pandas …plain and simple
throwaway19293883@reddit
Pandas/polars
musicman116@reddit
Off the top of my head, I'm pretty sure pandas can do most if not all of this. If you need something with more efficient performance, then maybe try polars.
JBalloonist@reddit
Pandas can do all of this.