Skip to content

Commit

Permalink
Align columns better with values padded up to 12 digits
Browse files Browse the repository at this point in the history
Restrict number of significant digits to 7, larger numbers as exponents
  • Loading branch information
West Jens authored and West Jens committed Apr 7, 2021
1 parent 0c7f4b9 commit 5fd912f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Scripts/datahandling/resultdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ def flush(self):
self._line_buffer[filename].close()
self._line_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 @@ -46,6 +50,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 Down Expand Up @@ -87,7 +92,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

0 comments on commit 5fd912f

Please sign in to comment.