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.

astropy.io.ascii does not read pandas csv file correctly

See original GitHub issue

Pandas by default will write CSV files where the header for the first column is missing:

In [4]: from pandas import DataFrame

In [5]: df = DataFrame()

In [6]: df['a'] = [1,2,3]

In [7]: df.to_csv('test.csv')

In [8]: %more test.csv
,a
0,1
1,2
2,3

Whether or not this is sensible is debatable, but this means there are a lot of CSV files in the wild missing the first header column name. Astropy doesn’t read these in correctly though:

In [10]: from astropy.io.ascii import read

In [11]: read('test.csv')
Out[11]: 
<Table masked=True length=4>
 col1 col2
int64 str1
----- ----
   --    a
    0    1
    1    2
    2    3

I think we might want to special case this, or deal better with cases like this given how common these kinds of files are going to be.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
drdavellacommented, Oct 9, 2017

@pllim, I don’t think it’s a bug. I think it’s the way that pandas indicates that the first column in a csv is an index, not a real data column. It’s possible to give the index column a name, but I believe it’s None by default. See the docs here:

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html

0reactions
drdavellacommented, Oct 9, 2017

I could volunteer to look into this since I think I’d probably learn something new/useful. But if someone else already has a handle on a fix, that’s okay too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading Tables — Astropy v5.2
The fast C-readers do not support unicode. For large data files containing unicode, we recommend reading the file using pandas and converting to...
Read more >
Unable to read in big csv file · Issue #7871 · astropy ... - GitHub
It took a while to read in which chunks, but it worked and now the overall memory print is smaller than it was...
Read more >
Best way to read and write CSV files utilizing astroquery to ...
My first stab at this was defining a writeCsvFile() function, but this did not work properly to write a csv file. My next...
Read more >
ASCII Tables (astropy.io.ascii) - Read the Docs
io.ascii provides methods for reading and writing a wide range of ASCII data table formats via built-in Extension Reader classes. The emphasis is...
Read more >
Week 14 - Astropy - | notebook.community
Astropy is a package that is meant to provide a lot of basic functionality for astronomy work in Python. This can be roughly...
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