[FEA] Support list types in "to_csv"
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
**Example**:
```
import cudf
df = cudf.DataFrame({'id': [0, 1], 'list_col': [[0, 0], [1, 1]]})
df.to_csv('test.csv')
```
**Result**:
```
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
in
1 df = cudf.DataFrame({'id': [0, 1], 'list_col': [[0, 0], [1, 1]]})
----> 2 df.to_csv('test.csv')
/conda/lib/python3.8/site-packages/cudf/core/dataframe.py in to_csv(self, path_or_buf, sep, na_rep, columns, header, index, line_terminator, chunksize, encoding, compression, **kwargs)
7366 from cudf.io import csv as csv
7367
-> 7368 return csv.to_csv(
7369 self,
7370 path_or_buf=path_or_buf,
/conda/lib/python3.8/contextlib.py in inner(*args, **kwds)
73 def inner(*args, **kwds):
74 with self._recreate_cm():
---> 75 return func(*args, **kwds)
76 return inner
77
/conda/lib/python3.8/site-packages/cudf/io/csv.py in to_csv(df, path_or_buf, sep, na_rep, columns, header, index, line_terminator, chunksize, encoding, compression, **kwargs)
157 for col in df._data.columns:
158 if isinstance(col, cudf.core.column.ListColumn):
--> 159 raise NotImplementedError(
160 "Writing to csv format is not yet supported with "
161 "list columns."
NotImplementedError: Writing to csv format is not yet supported with list columns.
```
Pandas does this by wrapping a stringified representation of each row's list `quotechar`:
```
import pandas as pd
df = pd.DataFrame({'id': [0, 1], 'list_col': [[0, 0], [1, 1]]})
df.to_csv('test.csv')
```
test.csv:
```
,id,list_col
0,0,"[0, 0]"
1,1,"[1, 1]"
```
Contributor guide
Assessment
This issue has not been assessed yet.