Commit 12e099df by rakesh.pv

build

parent 3753acb7
import json
import pandas as pd
def json_merge():
try:
data = pd.read_csv("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv")
split_one = data[["Timestamp", "kWh"]]
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))
import json import json
import pandas as pd
def json_parsing():
try:
data = pd.read_csv("C:/Users/rakesh.pv/PycharmProjects/pythonProject1/scripts/temp/task3.csv")
first_ten_rows = data.iloc[:10]
last_ten_rows = data.iloc[-10:]
dataframe = pd.concat([first_ten_rows, last_ten_rows], axis=0, ignore_index=True)
#
dataframe['Timestamp'] = dataframe["Timestamp"].apply(lambda x: pd.to_datetime(x)
.strftime('%Y-%m-%d %H:%M:%S'))
print(dataframe)
# convert dataframe into JSON file
header = list(dataframe.columns)
keys = ['column1', 'column2', 'column2', 'column3', 'column5', 'column6']
body = {"body": dataframe.to_dict(orient='records')}
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))
from scripts.core.handlers.json_concat import json_merge
from scripts.core.handlers.json_parser import json_parsing
choice = int(input(
"JSON operations \n1.json Parsing \n2.json merging \n3.melting data\n4.concat pivot\nChoose your choice\n"))
if choice == 1:
json_parsing()
choice=int(input("JSON operations \n1.json Parsing \n2.json melting \n3.melting data\n4.concat two data items\nChoose your choice\n")) elif choice == 2:
if choice==1: json_merge()
elif choice == 3:
print() print()
elif choice==2: elif choice == 4:
print()
elif choice==3:
print()
elif choice==4:
print() 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