Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
YAPSUT
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
Michele Maris
YAPSUT
Commits
73b28975
Commit
73b28975
authored
11 months ago
by
Michele Maris
Browse files
Options
Downloads
Patches
Plain Diff
u
parent
6d35c8df
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
src/yapsut/ya_extended_csv.py
+23
-7
23 additions, 7 deletions
src/yapsut/ya_extended_csv.py
with
23 additions
and
7 deletions
src/yapsut/ya_extended_csv.py
+
23
−
7
View file @
73b28975
from
collections
import
OrderedDict
import
pandas
class
ya_extended_csv
:
"""
Yet Another extended csv manages
extended csv is csv with:
...
...
@@ -33,17 +38,14 @@ declares the python interpreter
the separator can be a single character or a sequence
"""
from
collections
import
OrderedDict
import
pandas
class
ya_extended_csv
:
@property
def
header
(
self
)
:
"""
returns the header
"""
return
self
.
_header
#
@property
def
skipUndef
(
self
)
:
"""
get/set the skipUndef flag
"""
return
self
.
_skipUndef
@skipUndef.setter
def
skipUndef
(
self
,
this
)
:
...
...
@@ -51,6 +53,7 @@ class ya_extended_csv :
#
@property
def
sep
(
self
)
:
"""
get/set the separator
"""
return
self
.
_sep
#
@sep.setter
...
...
@@ -59,11 +62,13 @@ class ya_extended_csv :
#
@property
def
reserved_tags
(
self
)
:
"""
list of tags reserved (can not be used by the user)
"""
return
[
'
creator
'
,
'
created
'
,
'
creator_version
'
,
'
header_version
'
,
'
sep
'
,
'
tag_comment
'
,
'
tag_variable
'
,
'
filename
'
,
'
author
'
,
'
!__index_label
'
,
'
!__sep__
'
,
'
!__tag_comment__
'
,
'
!__tag_variable__
'
,
'
!__assign_operator__
'
,
'
!__index_label__
'
]
#
@property
def
doNotLoadTags
(
self
)
:
"""
list of tags not to be loaded
"""
return
[
'
BEGIN
'
,
'
END
'
,
'
!__index_label
'
,
'
!__sep__
'
,
'
!__tag_comment__
'
,
'
!__tag_variable__
'
,
'
!__assign_operator__
'
,
'
!__index_label__
'
]
#
def
__init__
(
self
,
sep
=
'
,
'
,
tag_comment
=
'
#
'
,
tag_variable
=
'
#!
'
,
assign_operator
=
'
=
'
,
skipUndef
=
True
,
undefValue
=
None
,
index_column
=
0
)
:
...
...
@@ -111,21 +116,32 @@ syntax elements can be changed modifiing parameters
if
not
self
.
_skipUndef
:
self
.
_header
[
a
]
=
self
.
_undefValue
#
@property
def
hdr_to_str
(
self
)
:
"
header converted to string, fields separed by
'
\n
'
.
"
if
len
(
self
.
_header
.
keys
())
==
0
:
return
""
out
=
[
k
+
'
=
'
+
str
(
self
.
_header
[
k
])
for
k
in
self
.
_header
.
keys
()]
return
'
\n
'
.
join
(
out
)
#
def
get_data
(
self
,
sep
)
:
"
get the data
"
engine
=
'
c
'
if
len
(
sep
)
==
1
else
'
python
'
if
self
.
_verbose
:
print
(
engine
,
sep
)
self
.
_csv
=
pandas
.
read_csv
(
self
.
_fname
,
sep
=
sep
,
comment
=
self
.
_tag_comment
,
engine
=
engine
,
index_col
=
self
.
_index_column
)
#
def
set_pandas_attrs
(
self
)
:
"
set the .attrs dictionary of pandas table
"
if
len
(
self
.
_header
.
keys
())
>
0
:
for
k
in
self
.
_header
.
keys
()
:
if
k
not
in
self
.
doNotLoadTags
:
self
.
_csv
.
attrs
[
k
]
=
self
.
_header
[
k
]
#
def
to_pandas
(
self
)
:
"
to pandas table
"
return
self
.
_csv
#
def
to_dict
(
self
)
:
"
to dictionary
"
out
=
OrderedDict
()
for
k
in
self
.
_csv
.
keys
()
:
out
[
k
]
=
self
.
_csv
[
k
].
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