Joris Van den Bossche created ARROW-10805:
---------------------------------------------
Summary: [C++] CSV reader: option to ignore trailing delimiters
Key: ARROW-10805
URL: https://issues.apache.org/jira/browse/ARROW-10805
Project: Apache Arrow
Issue Type: Improvement
Components: C++
Reporter: Joris Van den Bossche
It is not uncommon to have a CSV file that has "trailing" delimiters.
For example, I ran into something like this:
{code}
1|2|3|
4|5|6|
{code}
where we currently detect 4 columns. If you want to properly read this in while
passing the column names, you need to add a "dummy" column name for the
non-existing last column (and specify the actual column names to
{{include_columns}} to drop it again):
{code:python}
column_names = [...]
csv.read_csv(
"path/to/dile.csv",
read_options=csv.ReadOptions(column_names=column_names + ["dummy"]),
parse_options=csv.ParseOptions(delimiter="|"),
convert_options=csv.ConvertOptions(include_columns=column_names)
)
{code}
Pandas has indirect support for it through the {{index_col=False}} option (see
https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#index-columns-and-trailing-delimiters,
i.e. when the length of the names is 1 shorter as the detected number of
columns and this last column is all empty, it will drop this)
Although the above provides a workaround, it might be nice to have out of the
box support for it.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)