Commit 6d87d9e1 by arun.uday

all

parent 70f50136
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task5)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task5 - Copy)" project-jdk-type="Python SDK" />
</project> </project>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/task5.iml" filepath="$PROJECT_DIR$/.idea/task5.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/task5pandas_op.iml" filepath="$PROJECT_DIR$/.idea/task5pandas_op.iml" />
</modules> </modules>
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.9 (task5 - Copy)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -9,11 +9,11 @@ def time_change(file): ...@@ -9,11 +9,11 @@ def time_change(file):
file_copy['Timestamp'] = file_copy['Timestamp'].dt.strftime(date_format) file_copy['Timestamp'] = file_copy['Timestamp'].dt.strftime(date_format)
# for storing the pivoted frame to dictionary # for storing the pivoted frame to dictionary
dict_cols = {} dict_cols = []
for i in range(0, len(file_copy.columns)): for i in range(0, len(file_copy.columns)):
key_dict = "label" + str(i) key_dict = file_copy.columns[i]
val_dict = file_copy.columns[i] val_dict = file_copy.columns[i].lower()
dict_cols.update({key_dict: val_dict}) dict_cols.append({key_dict: val_dict})
# storing the header and body to json # storing the header and body to json
head_cols = {"header": dict_cols} head_cols = {"header": dict_cols}
......
...@@ -5,14 +5,15 @@ def melt_frame(file): ...@@ -5,14 +5,15 @@ def melt_frame(file):
file_copy = file file_copy = file
# creating the melted dataframe melted_file # creating the melted dataframe melted_file
melted_file = file_copy.melt(id_vars=['Timestamp'], value_vars=['kWh']) melted_file = file_copy.melt(id_vars=['Timestamp'])
print(melted_file)
# for storing the melted frame to dictionary # for storing the melted frame to dictionary
dict_cols = {} dict_cols = []
for i in range(0, len(melted_file.columns)): for i in range(0, len(melted_file.columns)):
key_dict = "label" + str(i) key_dict = "label" + str(i)
val_dict = melted_file.columns[i] val_dict = melted_file.columns[i]
dict_cols.update({key_dict: val_dict}) dict_cols.append({key_dict: val_dict})
# storing the header and body to json # storing the header and body to json
head_cols = {"header": dict_cols} head_cols = {"header": dict_cols}
......
...@@ -11,13 +11,14 @@ def merge_frame(file): ...@@ -11,13 +11,14 @@ def merge_frame(file):
# creating the merged dataframe merged_file # creating the merged dataframe merged_file
merged_file = pd.merge(file_frame1, file_frame2, on='Timestamp') merged_file = pd.merge(file_frame1, file_frame2, on='Timestamp')
print(merged_file)
# for storing the merged frame to dictionary # for storing the merged frame to dictionary
dict_cols = {} dict_cols = []
for i in range(0, len(merged_file.columns)): for i in range(0, len(merged_file.columns)):
key_dict = "label" + str(i) key_dict = "label" + str(i)
val_dict = merged_file.columns[i] val_dict = merged_file.columns[i]
dict_cols.update({key_dict: val_dict}) dict_cols.append({key_dict: val_dict})
# storing the header and body to json # storing the header and body to json
head_cols = {"header": dict_cols} head_cols = {"header": dict_cols}
......
...@@ -3,18 +3,16 @@ ...@@ -3,18 +3,16 @@
def pivot_frame(file): def pivot_frame(file):
file_copy = file file_copy = file
# pivoting the data # pivoting the data
pivoted_d = file_copy.pivot_table(index='Timestamp', columns=[], pivoted_d = file_copy.pivot_table(index='Timestamp', columns=[],
values=file_copy) values=file_copy)
print(pivoted_d)
# for storing the pivoted frame to dictionary # for storing the pivoted frame to dictionary
dict_cols = {} dict_cols = []
for i in range(0, len(pivoted_d.columns)): for i in range(0, len(pivoted_d.columns)):
key_dict = "label"+str(i) key_dict = "label"+str(i)
val_dict = pivoted_d.columns[i] val_dict = pivoted_d.columns[i]
dict_cols.update({key_dict: val_dict}) dict_cols.append({key_dict: val_dict})
# storing the header and body to json # storing the header and body to json
head_cols = {"header": dict_cols} head_cols = {"header": dict_cols}
body_vals = {"body": pivoted_d.to_dict(orient="records")} body_vals = {"body": pivoted_d.to_dict(orient="records")}
......
{ {
"header": { "header": [
"label0": "Timestamp", {
"label1": "kW", "label0": "Timestamp"
"label2": "kVA" },
}, {
"label1": "kW"
},
{
"label2": "kVA"
}
],
"body": [ "body": [
{ {
"Timestamp": "01-12-19 00-00-21", "Timestamp": "01-12-19 00-00-21",
......
{ {
"header": { "header": [
"label0": "current", {
"label1": "kVA", "label0": "current"
"label2": "kVAh", },
"label3": "kW", {
"label4": "kWh" "label1": "kVA"
}, },
{
"label2": "kVAh"
},
{
"label3": "kW"
},
{
"label4": "kWh"
}
],
"body": [ "body": [
{ {
"current": 281.58292388916016, "current": 281.58292388916016,
......
{ {
"header": { "header": [
"label0": "Timestamp", {
"label1": "kWh", "Timestamp": "timestamp"
"label2": "kVAh", },
"label3": "kW", {
"label4": "kVA", "kWh": "kwh"
"label5": "current" },
}, {
"kVAh": "kvah"
},
{
"kW": "kw"
},
{
"kVA": "kva"
},
{
"current": "current"
}
],
"body": [ "body": [
{ {
"Timestamp": "01-12-19 00-00-21", "Timestamp": "01-12-19 00-00-21",
......
...@@ -18,14 +18,14 @@ def access_op(): ...@@ -18,14 +18,14 @@ def access_op():
print("Pivoting the dataframe") print("Pivoting the dataframe")
dict_data_pivoted, pivot_change = json_pandas.pivot_data(file_concat) dict_data_pivoted, pivot_change = json_pandas.pivot_data(file_concat)
json_pandas.create_json(path_pivot, pivot_change) json_pandas.create_json(path_pivot, dict_data_pivoted)
print("Melting the dataframe") print("Melting the dataframe")
melt_change = json_pandas.melt_data(dict_data_pivoted) melt_change = json_pandas.melt_data(file_concat)
json_pandas.create_json(path_melt, melt_change) json_pandas.create_json(path_melt, melt_change)
print("Merging the dataframe") print("Merging the dataframe")
merge_change = json_pandas.merge_data(dict_data_pivoted) merge_change = json_pandas.merge_data(file_concat)
json_pandas.create_json(path_merge, merge_change) json_pandas.create_json(path_merge, merge_change)
except Exception as e: except Exception as e:
......
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