logo
Browse Source

Add csv reader

Signed-off-by: junjie.jiang <junjie.jiang@zilliz.com>
main
junjie.jiang 2 years ago
parent
commit
b7905ff441
  1. 4
      __init__.py
  2. 20
      read_csv.py

4
__init__.py

@ -0,0 +1,4 @@
from .read_csv import ReadCSV
def csv_reader(*args, **kwargs):
ReadCSV(*args, **kwargs)

20
read_csv.py

@ -0,0 +1,20 @@
import csv
from towhee.operator import PyOperator
class ReadCSV(PyOperator):
"""
Wrapper of python csv: https://docs.python.org/3.8/library/csv.html
"""
def __init__(self, f_path: str, newline='', dialect='excel', **fmtparams):
self._f_path = f_path
self._newline = newline
self._dialect = dialect
self._fmtparams = fmtparams
def __call__(self):
with open(self._f_path, newline=self._newline) as f:
reader = csv.reader(f, self._dialect, **self._fmtparams)
# skip header
next(reader)
yield from reader
Loading…
Cancel
Save