File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Scripts/Miscellaneous/JSONtoExcel Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
# Importing Pandas and json
6
6
import json
7
- import pandas as pd
7
+ from pandas import DataFrame
8
+ import os
8
9
# Importing the data from a file using the load method
9
- with open ('./sampleData.json' ) as json_file :
10
- data = json .load (json_file )
11
- # Creating a dataframe
12
- df = pd .DataFrame (data )
13
- df .to_excel ('./exported_json_data.xlsx' )
10
+ def convert (inp_json_file :str ) -> None :
11
+ """Simple function to convert any .json file to a xlsx file of any name"""
12
+ with open (inp_json_file ) as json_file :
13
+ data = json .load (json_file )
14
+ # Creating a dataframe
15
+ df = DataFrame (data )
16
+ out_xlsx_file = inp_json_file [:- 4 ] + 'xlsx'
17
+ df .to_excel (out_xlsx_file )
18
+
19
+ if __name__ == "__main__" :
20
+ convert (os .path .join ((os .path .abspath ("." )),"Python_and_the_web\Scripts\Miscellaneous\JSONtoExcel\sampleData.json" ))
You can’t perform that action at this time.
0 commit comments