Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align columns better with values padded up to 12 digits #283

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Scripts/datahandling/resultdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ def flush(self):
f.write(row)
self._list_buffer = {}
for filename in self._df_buffer:
self._df_buffer[filename].to_csv(
df = self._df_buffer[filename]
df.index = df.index.astype(str, copy=False)
# Pad index according to its longest item
df.index = df.index.str.pad(len(max(df.index, key=len)))
df.to_csv(
os.path.join(self.path, filename),
sep='\t', float_format="%1.5f")
sep='\t', na_rep=12*' ', float_format="%12.7g")
self._df_buffer = {}
for filename in self._xlsx_buffer:
self._xlsx_buffer[filename].save(
Expand All @@ -48,6 +52,7 @@ def print_data(self, data, filename, colname):
colname : str
Desired name of this column
"""
colname = colname.rjust(12)
if filename not in self._df_buffer:
self._df_buffer[filename] = pandas.DataFrame(data, columns=[colname])
else:
Expand All @@ -74,7 +79,7 @@ def print_matrix(self, data, filename, sheetname):
# If no Workbook module available (= _use_txt), save data to csv
data.to_csv(
os.path.join(self.path, "{}_{}.txt".format(filename, sheetname)),
sep='\t', float_format="%8.1f")
sep='\t', float_format="%12.7g")
else:
# Get/create new worksheet
if filename in self._xlsx_buffer:
Expand Down