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
2080c1c8
Commit
2080c1c8
authored
Jan 30, 2023
by
rakesh.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
c07ec4df
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
8 deletions
+37
-8
scripts/core/handlers/json_concat.py
+1
-2
scripts/core/handlers/json_data_melting.py
+1
-2
scripts/core/handlers/json_file.py
+33
-0
scripts/core/handlers/json_parser.py
+2
-3
scripts/core/handlers/json_pivot.py
+0
-0
scripts/core/services/app.py
+0
-1
No files found.
scripts/core/handlers/json_concat.py
View file @
2080c1c8
...
...
@@ -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
))
scripts/core/handlers/json_data_melting.py
View file @
2080c1c8
...
...
@@ -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
))
scripts/core/handlers/json_file.py
0 → 100644
View file @
2080c1c8
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
scripts/core/handlers/json_parser.py
View file @
2080c1c8
...
...
@@ -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
()
scripts/core/handlers/json_pivot.py
deleted
100644 → 0
View file @
c07ec4df
scripts/core/services/app.py
View file @
2080c1c8
...
...
@@ -6,7 +6,6 @@ choice = int(input(
"JSON operations
\n
1.json Parsing
\n
2.json merging
\n
3.melting data
\n
Choose your choice
\n
"
))
if
choice
==
1
:
json_parsing
()
elif
choice
==
2
:
json_merge
()
elif
choice
==
3
:
...
...
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