1
$\begingroup$

I want to obtain data from https://petition.parliament.uk/petitions/250967 but the data format is Json. I am new to data mining and I would like to know if there is a way to convert this data into an excel format. Thanks for your time.

$\endgroup$

2 Answers 2

0
$\begingroup$

Here is a tutorial by Corey Schafer on working with JSON data. He explains in detail how to convert JSON data into python objects, but I don't think he explains how to convert them to excel here. But if you are familiar with pandas, you should be able to create dataframes and then convert them to excel files as needed.

$\endgroup$
0
$\begingroup$

Here you have an example I made for you, I hope it is useful:

test json (i.e. a dictionary structure)

test_info = {
                "menu_2_people": {
                    "potatoes": "3kg",
                    "tomatoes": "1kg",
                    "peppers": "0.5kg"
                    },
                "menu_4_people": {
                    "potatoes": "5kg",
                    "tomatoes": "2kg",
                    "peppers": "1kg"
                }
            }

print('test_info type {}'.format(type(test_info)))

### convert it into a dataframe
import pandas as pd

dict_to_df = pd.DataFrame(test_info)
print('dict_to_df type {}'.format(type(test_info)))

### use Pandas excel writer to create an excel file from the dataframe
writer = pd.ExcelWriter('test_info.xlsx', engine='xlsxwriter')
dict_to_df.to_excel(writer)
writer.save()

After this, you should be able to find the xlsx file in the same directory. Important to note is the structure of your data; in this example, there are 2 key-value pairs with the same items, but a json could be more complicated, and this would probably mean a multiindex dataframe for instance... can you give us an example of what you have to convert?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.