官术网_书友最值得收藏!

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 mongoimport. I highly recommend the first and much easier option.

How it works…

This recipe works almost exactly like our previous recipe for importing a CSV file; only here, we start with an Excel file, which we save as a CSV file.

主站蜘蛛池模板: 阿勒泰市| 普兰店市| 杨浦区| 鹤庆县| 滁州市| 达尔| 泗阳县| 萨迦县| 枣庄市| 堆龙德庆县| 武陟县| 伊宁市| 康平县| 慈溪市| 宁河县| 托里县| 九龙城区| 蓬溪县| 左贡县| 巴青县| 梅州市| 永胜县| 东海县| 张家界市| 石林| 开远市| 耒阳市| 杭锦旗| 石门县| 琼结县| 万宁市| 渝中区| 合川市| 衡东县| 安庆市| 平舆县| 乳山市| 保山市| 甘孜| 东兴市| 浦北县|