Importing an Excel file into MongoDB

MongoDB does not support the direct import of Excel files, so to do that, we will use a function built into Excel.

Getting ready

The mongoimport utility supports only JSON, CSV, and TSV files. Therefore, to get your data from Excel into MongoDB, the best option is to save it as a CSV file, and then use mongoimport to import it.

How to do it…

In Excel:

  1. Go to the File menu.
  2. Select Save As.
  3. Save the file in the Comma Separated Values (CSV) format.

After you perform the preceding steps, you can use the previous recipe to import the file.

If you think that's too easy though, you can import the Excel file into a Pandas DataFrame using read_excel, write the entire DataFrame to a CSV file using to_csv, and then import it using ...

Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.