stanleyjs opened a new issue, #34282:
URL: https://github.com/apache/arrow/issues/34282
### Describe the usage question you have. Please include as many useful
details as possible.
Hi,
I have a batch of csvs I'd like to read using pyarrow's multithreaded
engine. Unfortunately, the header row of these files doesn't have the same
number of columns as the rest of the data, which has an unlabeled index column.
Pyarrow does not like csvs with unexpected number of columns.
These csvs are large datasets generated by bioinformatics pipelines - like
60k x 50k.
What's the best way to handle this? My usecase does not really allow
permanent modification of the csvs (they get pulled from an external server),
so I can't just fix them at the souce.
Here is my best attempt.
```
import pyarrow.csv as csv
from io import BytesIO
def read_csv_short_header(fname,delim=b','):
if isinstance(delim, str):
delim.encode()
with open(fname,'rb') as f:
#extract the first two lines so we can compare and fix.
l1 = f.readline()
l2 = f.readline()
#get the rest of the data
dat = f.read()
#fix the missing columns
extra_column =0
while len(l1.split(delim)) < len(l2.split(delim)):
extra_column += 1
l1 = f'column{extra_column}\t'.encode() + l1
#full data with new columns in header
dat = l1+b'\n'+l2+b'\n'+dat
parse_options = csv.ParseOptions(delimiter=delim)
return csv.read_csv(BytesIO(dat),parse_options=parse_options)
```
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]