Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json_operation_python
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rakesh.pv
json_operation_python
Commits
c07ec4df
Commit
c07ec4df
authored
Jan 27, 2023
by
rakesh.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build : code is net referred
parent
12e099df
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
9 deletions
+25
-9
scripts/core/handlers/json_concat.py
+2
-2
scripts/core/handlers/json_data_melting.py
+16
-0
scripts/core/handlers/json_parser.py
+3
-3
scripts/core/services/app.py
+4
-4
No files found.
scripts/core/handlers/json_concat.py
View file @
c07ec4df
...
@@ -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
))
scripts/core/handlers/json_data_melting.py
View file @
c07ec4df
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
))
scripts/core/handlers/json_parser.py
View file @
c07ec4df
...
@@ -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
()
scripts/core/services/app.py
View file @
c07ec4df
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
\n
1.json Parsing
\n
2.json merging
\n
3.melting data
\n
4.concat pivot
\n
Choose your choice
\n
"
))
"JSON operations
\n
1.json Parsing
\n
2.json merging
\n
3.melting data
\n
Choose 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"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment