Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-server
Commits
a7a39b33
Verified
Commit
a7a39b33
authored
5 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP load tsv from file
parent
af7d933b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripting/bin/xls_from_csv.py
+7
-16
7 additions, 16 deletions
scripting/bin/xls_from_csv.py
with
7 additions
and
16 deletions
scripting/bin/xls_from_csv.py
+
7
−
16
View file @
a7a39b33
...
@@ -31,27 +31,18 @@ import sys
...
@@ -31,27 +31,18 @@ import sys
import
pandas
as
pd
import
pandas
as
pd
def
_parse_to_dataframe
(
c
sv_
string
):
def
_parse_to_dataframe
(
t
sv_
file
):
"""
Attempts to create a valid dataframe from a
C
SV
string
.
"""
Attempts to create a valid dataframe from a
T
SV
file
.
The CSV string typically starts with a header like this:
```
data:text/csv;charset=utf-8,colname1 colname2
value1 value2
...
``
`
Parameters
Parameters
----------
----------
c
sv_
string
:
The
URL
encoded
CSV
content
,
starts
with
`data:text/csv`
.
t
sv_
file : path to a tsv file
.
Returns
Returns
-------
-------
out : The created dataframe.
out : The created dataframe.
"""
"""
csv_string
=
csv_string
.
split
(
"
,
"
)[
1
]
dataframe
=
pd
.
read_csv
(
tsv_file
,
sep
=
"
\t
"
)
sio
=
io
.
StringIO
(
csv_string
)
dataframe
=
pd
.
read_csv
(
sio
,
sep
=
"
\t
"
)
return
dataframe
return
dataframe
...
@@ -100,15 +91,15 @@ def _parse_arguments():
...
@@ -100,15 +91,15 @@ def _parse_arguments():
tempdir
=
os
.
environ
[
"
SHARED_DIR
"
]
tempdir
=
os
.
environ
[
"
SHARED_DIR
"
]
parser
.
add_argument
(
'
-t
'
,
'
--tempdir
'
,
required
=
False
,
default
=
tempdir
,
parser
.
add_argument
(
'
-t
'
,
'
--tempdir
'
,
required
=
False
,
default
=
tempdir
,
help
=
"
Temporary dir for saving the result.
"
)
help
=
"
Temporary dir for saving the result.
"
)
parser
.
add_argument
(
'
-u
'
,
'
--urlencoded
'
,
required
=
True
,
help
=
"
The URL encoded csv data.
"
)
parser
.
add_argument
(
'
-a
'
,
'
--auth-token
'
,
required
=
False
,
parser
.
add_argument
(
'
-a
'
,
'
--auth-token
'
,
required
=
False
,
help
=
"
An authentication token (not needed, only for compatibility).
"
)
help
=
"
An authentication token (not needed, only for compatibility).
"
)
parser
.
add_argument
(
'
tsv
'
,
required
=
True
,
help
=
"
The tsv file.
"
)
return
parser
.
parse_args
()
return
parser
.
parse_args
()
def
main
():
def
main
():
args
=
_parse_arguments
()
args
=
_parse_arguments
()
dataframe
=
_parse_to_dataframe
(
args
.
urlencoded
)
dataframe
=
_parse_to_dataframe
(
args
.
tsv
)
filename
=
_write_xls
(
dataframe
,
directory
=
args
.
tempdir
)
filename
=
_write_xls
(
dataframe
,
directory
=
args
.
tempdir
)
print
(
filename
)
print
(
filename
)
...
...
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