Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSCT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dsa2-gunasinha
CSCT
Commits
f1ebc03c
Commit
f1ebc03c
authored
2 years ago
by
amilashanaka
Browse files
Options
Downloads
Patches
Plain Diff
convert to dataframe
parent
45c7906f
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
API/run.py
+19
-1
19 additions, 1 deletion
API/run.py
Data/data_process.py
+70
-0
70 additions, 0 deletions
Data/data_process.py
Data/input_data.json
+15122
-0
15122 additions, 0 deletions
Data/input_data.json
with
15211 additions
and
1 deletion
API/run.py
+
19
−
1
View file @
f1ebc03c
...
@@ -46,10 +46,28 @@ import pmdarima as pm
...
@@ -46,10 +46,28 @@ import pmdarima as pm
def
start
():
def
start
():
# read incomming json data
data
=
request
.
get_json
()
data
=
request
.
get_json
()
# convert json data into pandas data structure
data_arr
=
json
.
dumps
(
data
)
df
=
pd
.
read_json
(
data_arr
)
df
=
df
.
transpose
()
df
.
rename
(
columns
=
{
'
Product_Code
'
:
'
ProductCode
'
,
'
Product_Category
'
:
'
ProductCategory
'
,
'
Order_Demand
'
:
'
OrderDemand
'
},
inplace
=
True
)
#check is null
df
.
isnull
().
sum
()
return
data
# remove nan values
df
.
dropna
(
inplace
=
True
)
print
(
df
.
isnull
().
sum
())
return
data_arr
def
read_json
(
income_data
):
def
read_json
(
income_data
):
...
...
This diff is collapsed.
Click to expand it.
Data/data_process.py
0 → 100644
+
70
−
0
View file @
f1ebc03c
import
csv
import
json
import
pandas
as
pd
from
pymongo
import
MongoClient
# # get client instence
# client = MongoClient()
# # Connect to database
# db=client.station
# #create station collection
# station = db.station
# # Read csv file to pandas data frame
# df=pd.read_csv("product_demnd.csv",engine='python')
# # df = df.rename({'Unnamed: 0.1':'ID','Unnamed: 0': 'Read ID'}, axis=1)
# #Set Data Frame index to ID
# df=df.set_index('ID')
# #save to csv file
# df.to_csv('out.csv')
#function convert to csv file to json file
def
make_json
(
csvFilePath
,
jsonFilePath
):
# create a data dictionary
data
=
{}
# Open a csv reader called DictReader
with
open
(
csvFilePath
,
encoding
=
'
utf-8
'
)
as
csvf
:
csvReader
=
csv
.
DictReader
(
csvf
)
# Convert each row into a dictionary
# and add it to data
for
rows
in
csvReader
:
# Assuming a column named 'ID' to
# be the primary key
key
=
rows
[
'
Product_Code
'
]
data
[
key
]
=
rows
# Open a json writer, and use the json.dumps()
# function to dump data
with
open
(
jsonFilePath
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
jsonf
:
jsonf
.
write
(
json
.
dumps
(
data
,
indent
=
4
))
#call function convert csv file to json file format
make_json
(
'
product__demnd.csv
'
,
'
input_data.json
'
)
# file_data= []
# #open json file and read each line to json object
# with open('nosql.json') as f:
# file_data.append(json.load(f))
# #inset each object to station collection
# station.insert_many(file_data)
This diff is collapsed.
Click to expand it.
Data/input_data.json
0 → 100644
+
15122
−
0
View file @
f1ebc03c
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment