Commit c07ec4df by rakesh.pv

build : code is net referred

parent 12e099df
...@@ -10,7 +10,7 @@ def json_merge(): ...@@ -10,7 +10,7 @@ def json_merge():
split_two = data[["Timestamp", "kVA"]] split_two = data[["Timestamp", "kVA"]]
merge_data = pd.merge(split_one, split_two, on="Timestamp") merge_data = pd.merge(split_one, split_two, on="Timestamp")
body = {"merge file based on Timestamp ": merge_data.to_dict(orient='records')} 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: # with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv", 'w') as f:
json.dump(body, f, indent=4) # json.dump(body, f, indent=4)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
import json
import pandas as pd
def json_melt():
try:
data = pd.read_csv("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv")
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))
...@@ -23,10 +23,10 @@ def json_parsing(): ...@@ -23,10 +23,10 @@ def json_parsing():
json_header = {'header': dict(zip(keys, header))} json_header = {'header': dict(zip(keys, header))}
json_dict = {**json_header, **body} json_dict = {**json_header, **body}
with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.xlsx", 'w') as data: # with open("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.xlsx", 'w') as data:
json.dump(json_dict, data, indent=4) # json.dump(json_dict, data, indent=4)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
json_parsing()
from scripts.core.handlers.json_concat import json_merge from scripts.core.handlers.json_concat import json_merge
from scripts.core.handlers.json_data_melting import json_melt
from scripts.core.handlers.json_parser import json_parsing from scripts.core.handlers.json_parser import json_parsing
choice = int(input( choice = int(input(
"JSON operations \n1.json Parsing \n2.json merging \n3.melting data\n4.concat pivot\nChoose your choice\n")) "JSON operations \n1.json Parsing \n2.json merging \n3.melting data\nChoose your choice\n"))
if choice == 1: if choice == 1:
json_parsing() json_parsing()
elif choice == 2: elif choice == 2:
json_merge() json_merge()
elif choice == 3: elif choice == 3:
print() json_melt()
elif choice == 4:
print()
else: else:
print(" invalid option given") print(" invalid option given")
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