question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Human readable ecsv table

See original GitHub issue

I find the ecsv extremely useful, I’m a great fan of including units, comments and descriptions in the tables. The only downside of this format is that I can’t obtain a ecsv (with a comma as a delimiter, since it guarantees max compatibility) that has all the commas aligned. I realize that it is not in the specs of the format to have all the commas aligned, but researchers that I know, that are interested in using tables in astropy, are not adopting it because they can’t read the table with their eyes from the ASCII file. So they try to use fixed-size tables, which produce issue with descriptions and units, leading them to abandon any effort to switch to astropy tables.

I tried to experiment, and a MWE is:

from astropy.table import Table

a = np.array([1.20, 1.21, 2.22])
b = np.array(['u', 'g', 'egr'])
c = np.array([4.20, 1.00, 2.20])

t = Table()
t['a'] = a
t['b'] = b
t['c'] = c

t.write('tmp.txt', format='ascii.ecsv', delimiter=',', strip_whitespace=False,  overwrite=True)

resulting in

# ---
# datatype:
# - {name: a, datatype: float64}
# - {name: b, datatype: string}
# - {name: c, datatype: float64}
# delimiter: ','
# schema: astropy-2.0
a,b,c
1.2,u,4.2
1.21,g,1.0
2.22,egr,2.2

I modified the file astropy/astropy/io/ascii/ecsv.py of the tag v5.0.1, line 383, from return str(col[idx]) to return str(col[idx]).rjust(4) and as an output I get

# %ECSV 1.0
# ---
# datatype:
# - {name: a, datatype: float64}
# - {name: b, datatype: string}
# - {name: c, datatype: float64}
# delimiter: ','
# schema: astropy-2.0
a,b,c
 1.2,   u, 4.2
1.21,   g, 1.0
2.22, egr, 2.2

which is what I wanted. Of course this is not the way to go, and probably I’m breaking also something somewhere else, but would it be possible to obtain such a feature? My operating system is High Sierra, python 3.9.7 intel, numpy 1.21.2, astropy 5.0.1.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
taldcroftcommented, Jan 31, 2022

One possibility is allowing for column alignment in the space-delimited version of ECSV. In this case it is generally agreed that multiple spaces count as a single delimiter.

0reactions
taldcroftcommented, Feb 4, 2022

See #12821.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert .CSV files to a readable format
This article provides steps to convert or manage text files such as .CSV to a readable format.
Read more >
python - how to export data from a csv file in a human- ...
I have a csv file with fields that can have variable length. Is there a way to export it as a text file...
Read more >
informationsea/tableview: Format CSV file as human ...
Format CSV file as human readable table. Contribute to informationsea/tableview development by creating an account on GitHub.
Read more >
Going from a human readable Excel file to a machine- ...
Going from a human readable Excel file to a machine-readable csv with ... each sheet contains several tables that have lots of headers...
Read more >
PySpark Read CSV file into DataFrame
Table of contents: PySpark Read CSV file into DataFrame. Read multiple CSV files; Read all CSV files in a directory. Options while reading...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found