1
votes

For example, I have created an Excel file named “records.xlsx”

My Excel Data

Car Name   Price   Count
Honda       100     1
Tata        150     10
GMR         200      5

And I am importing it like this

import excel2json

excel2json.convert_from_file('records.xlsx')

Which is converting my excel file to following JSON:

[
    {
        "Car Name": "Honda",
        "Price": "100",
        "Count": "1"
    },
    {
        "Car Name": "Tata",
        "Price": "150",
        "Count": "10"
    },
    {
        "Car Name": "GMR",
        "Price": "150",
        "Count": "5"
    }
] 

I don't want the Price column in my resulting JSON. How can I convert this Excel file to JSON directly such that only columns Car Name and Count will appear in resulting JSON?

1
no actually am asking for suggestions in python script - Ansar Ahmed
stackoverflow.com/a/19167546/495157 - this answers the dropping part if you map whole thing to begin with - JGFMK
@JGFMK Thanks for this but Alexander Rossa Already suggested this to me and i don't want to convert whole excel to json.(kindly please read comments on this answer thanks ) - Ansar Ahmed

1 Answers

1
votes

The library that you are using doesn't seem to provide option to exclude column when loading it. I think the easiest thing for you to do would be to filter the unwanted column after you load the JSON.

your_json = excel2json.convert_from_file('records.xlsx')
for object in your_json:
    del object['Price']

You will be left with your_json without the Price entries.