Commit 2080c1c8 by rakesh.pv

changes

parent c07ec4df
......@@ -10,7 +10,6 @@ def json_merge():
split_two = data[["Timestamp", "kVA"]]
merge_data = pd.merge(split_one, split_two, on="Timestamp")
body = {"merge file based on Timestamp ": merge_data.to_dict(orient='records')}
# with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv", 'w') as f:
# json.dump(body, f, indent=4)
except Exception as e:
print(str(e))
......@@ -9,8 +9,7 @@ def json_melt():
melt_json = pd.melt(data, id_vars=["kW"], value_vars=["kVA"])
body = {"melting the data based on kW and kVA": melt_json.to_dict(orient='records')}
# with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv", 'w') as f:
# json.dump(body, f, indent=4)
except Exception as e:
print(str(e))
import pandas as pd
import json
from scripts.config.application_config import json_path
from scripts.core.handlers.create_new_dataframe import create_dataframe
def create_json_file(path):
try:
# Read the Excel file
dataframe = pd.read_excel(path)
dataframe['Timestamp'] = dataframe['Timestamp'].apply(lambda x: pd.to_datetime(x, unit='ms')
.strftime('%Y-%m-%d %H:%M:%S'))
new_dataframe = create_dataframe(dataframe)
# Setting "header" dictionary
keys = []
column_names = dataframe.columns.tolist()
for i in range(len(column_names)):
keys.append("column" + str(i))
header_dict = {'header': dict(zip(keys, column_names))}
# Setting 'body' dictionary
data = {"body": new_dataframe.to_dict(orient='records')}
json_dict = {**header_dict, **data}
print(json_dict)
# Create the JSON file
with open(json_path, "w") as json_file:
# Write data to the file
json.dump(json_dict, json_file, indent=4)
return True
except Exception as e:
print("Error: ", e)
return False
......@@ -23,10 +23,9 @@ def json_parsing():
json_header = {'header': dict(zip(keys, header))}
json_dict = {**json_header, **body}
# with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.xlsx", 'w') as data:
# json.dump(json_dict, data, indent=4)
except Exception as e:
print(str(e))
json_parsing()
json_parsing()
......@@ -6,7 +6,6 @@ choice = int(input(
"JSON operations \n1.json Parsing \n2.json merging \n3.melting data\nChoose your choice\n"))
if choice == 1:
json_parsing()
elif choice == 2:
json_merge()
elif choice == 3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment