Reads and parses the input of a csv stream or file. csv_file can be a filepath or an object that implements the iterator interface (defines next() or __next__() depending on python version). >>> seq.csv('examples/camping_purchases.csv').take(2) [['1', 'tent
(self, csv_file, dialect="excel", **fmt_params)
| 133 | return self(builtins.range(*args)) # pylint: disable=no-member |
| 134 | |
| 135 | def csv(self, csv_file, dialect="excel", **fmt_params): |
| 136 | """ |
| 137 | Reads and parses the input of a csv stream or file. |
| 138 | |
| 139 | csv_file can be a filepath or an object that implements the iterator interface |
| 140 | (defines next() or __next__() depending on python version). |
| 141 | |
| 142 | >>> seq.csv('examples/camping_purchases.csv').take(2) |
| 143 | [['1', 'tent', '300'], ['2', 'food', '100']] |
| 144 | |
| 145 | :param csv_file: path to file or iterator object |
| 146 | :param dialect: dialect of csv, passed to csv.reader |
| 147 | :param fmt_params: options passed to csv.reader |
| 148 | :return: Sequence wrapping csv file |
| 149 | """ |
| 150 | if isinstance(csv_file, str): |
| 151 | file_open = get_read_function(csv_file, self.disable_compression) |
| 152 | input_file = file_open(csv_file) |
| 153 | elif hasattr(csv_file, "next") or hasattr(csv_file, "__next__"): |
| 154 | input_file = csv_file |
| 155 | else: |
| 156 | raise ValueError( |
| 157 | "csv_file must be a file path or implement the iterator interface" |
| 158 | ) |
| 159 | |
| 160 | csv_input = csvapi.reader(input_file, dialect=dialect, **fmt_params) |
| 161 | return self(csv_input).cache(delete_lineage=True) |
| 162 | |
| 163 | def csv_dict_reader( |
| 164 | self, |