Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Temperaturverteilung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s39174
Temperaturverteilung
Commits
3d7fd9c1
Commit
3d7fd9c1
authored
3 years ago
by
Clemens Berteld
Browse files
Options
Downloads
Patches
Plain Diff
Cleaning up data
parent
3686de5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dataacquisition/ExportToDatabase.py
+4
-11
4 additions, 11 deletions
dataacquisition/ExportToDatabase.py
with
4 additions
and
11 deletions
dataacquisition/ExportToDatabase.py
+
4
−
11
View file @
3d7fd9c1
...
...
@@ -11,6 +11,8 @@ import psycopg2
import
psycopg2.extras
from
psycopg2
import
sql
from
psycopg2.extensions
import
ISOLATION_LEVEL_AUTOCOMMIT
import
pandas
as
pd
import
numpy
as
np
stationGPD
=
None
...
...
@@ -74,19 +76,10 @@ def insert_data(stationList):
columns
.
append
(
'"'
+
column
+
'"'
)
columns
=
str
(
columns
).
replace
(
'
[
'
,
''
).
replace
(
'
]
'
,
''
).
replace
(
"'"
,
""
).
replace
(
'
\n
'
,
''
).
replace
(
'
'
,
''
)
values
=
[]
for
value
in
df_columns
:
if
isinstance
(
value
,
str
):
value
=
value
.
replace
(
'
NaN
'
,
'
NULL
'
)
elif
isinstance
(
value
,
float
):
value
=
round
(
value
,
3
)
values
.
append
(
value
)
values
=
"
VALUES({})
"
.
format
(
"
,
"
.
join
(
values
))
stationList
=
stationList
.
round
(
decimals
=
3
)
# create VALUES('%s', '%s",...) one '%s' per column
#
values = "VALUES({})".format(",".join(["%s" for _ in df_columns]))
values
=
"
VALUES({})
"
.
format
(
"
,
"
.
join
([
"
%s
"
for
_
in
df_columns
]))
# create INSERT INTO table (columns) VALUES('%s',...)
insert_stmt
=
"""
INSERT INTO {} ({}) {}
"""
.
format
(
'
stations
'
,
columns
,
values
)
...
...
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