Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
toolbox
WindEnergyToolbox
Commits
3b042296
Commit
3b042296
authored
7 years ago
by
David Verelst
Browse files
Options
Downloads
Patches
Plain Diff
remove spaces from empty lines and trailing spaces
parent
627e4f2c
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
wetb/prepost/write_master.py
+14
-14
14 additions, 14 deletions
wetb/prepost/write_master.py
with
14 additions
and
14 deletions
wetb/prepost/write_master.py
+
14
−
14
View file @
3b042296
...
...
@@ -33,7 +33,7 @@ def write_master(path_to_texts,
excel_name
=
'
DLCs.xlsx
'
,
file_end
=
'
.txt
'
,
delimiter
=
'
\t
'
):
"""
Write a master Excel sheet from a series of text files
Args:
path_to_texts (str): path to directory with text files
excel_name (str): filename of generated master Excel file
...
...
@@ -44,33 +44,33 @@ def write_master(path_to_texts,
# formatting for header cells
header_dict
=
{
'
bold
'
:
True
,
'
font_color
'
:
'
#1F497D
'
,
'
bottom
'
:
2
,
'
bottom_color
'
:
'
#95B3D7
'
}
# get list of text files
text_files
=
[
f
for
f
in
os
.
listdir
(
path_to_texts
)
\
if
f
.
endswith
(
file_end
)]
# check if main text file in the specified directory
if
'
Main
'
+
file_end
not
in
text_files
:
raise
ValueError
(
'
\"
Main
\"
file not in CSV directory
'
)
# rearrange text files so main page is first and everything
# rearrange text files so main page is first and everything
# else is alphabetical
text_files
.
remove
(
'
Main
'
+
file_end
)
text_files
=
[
'
Main
'
+
file_end
]
+
sorted
(
text_files
)
# open excel file
writer
=
pd
.
ExcelWriter
(
excel_name
,
engine
=
'
xlsxwriter
'
)
# create workbook and add formast
workbook
=
writer
.
book
header
=
workbook
.
add_format
(
header_dict
)
# loop through text files
for
text_name
in
text_files
:
# define path to csv file
text_path
=
os
.
path
.
join
(
path_to_texts
,
text_name
)
# read data, write to Excel file, and define worksheet handle
text_df
=
pd
.
read_table
(
text_path
,
delimiter
=
delimiter
,
dtype
=
str
,
...
...
@@ -78,10 +78,10 @@ def write_master(path_to_texts,
text_df
.
to_excel
(
writer
,
sheet_name
=
text_name
.
rstrip
(
file_end
),
index
=
False
,
header
=
False
)
worksheet
=
writer
.
sheets
[
text_name
.
rstrip
(
file_end
)]
# get column widths by calculating max string lenths
col_widths
=
text_df
.
apply
(
lambda
x
:
np
.
max
([
len
(
str
(
s
))
for
s
in
x
]))
# add formatting
for
i_col
,
width
in
enumerate
(
col_widths
):
worksheet
.
set_column
(
i_col
,
i_col
,
width
)
...
...
@@ -92,10 +92,10 @@ def write_master(path_to_texts,
else
:
worksheet
.
set_row
(
1
,
cell_format
=
header
)
worksheet
.
set_zoom
(
zoom
=
85
)
# save worksheet
writer
.
save
()
return
if
__name__
==
'
__main__
'
:
...
...
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