Skip to content

Commit c70be12

Browse files
committed
fix[csv_parser]:missing header
1 parent 1620b4f commit c70be12

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

application/parser/file/tabular_parser.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ def parse_file(self, file: Path, errors: str = "ignore") -> Union[str, List[str]
104104
raise ValueError("pandas module is required to read CSV files.")
105105

106106
df = pd.read_csv(file, **self._pandas_config)
107+
headers = df.columns.tolist()
107108

108109
text_list = df.apply(
109-
lambda row: (self._col_joiner).join(row.astype(str).tolist()), axis=1
110+
lambda row: self._col_joiner.join(
111+
[f"{headers[i]}: {str(val)}" for i, val in enumerate(row)]
112+
),
113+
axis=1,
110114
).tolist()
111115

112116
if self._concat_rows:
@@ -169,12 +173,16 @@ def parse_file(self, file: Path, errors: str = "ignore") -> Union[str, List[str]
169173
raise ValueError("pandas module is required to read Excel files.")
170174

171175
df = pd.read_excel(file, **self._pandas_config)
176+
headers = df.columns.tolist()
172177

173178
text_list = df.apply(
174-
lambda row: (self._col_joiner).join(row.astype(str).tolist()), axis=1
179+
lambda row: self._col_joiner.join(
180+
[f"{headers[i]}: {str(val)}" for i, val in enumerate(row)]
181+
),
182+
axis=1,
175183
).tolist()
176184

177185
if self._concat_rows:
178186
return (self._row_joiner).join(text_list)
179187
else:
180-
return text_list
188+
return text_list

0 commit comments

Comments
 (0)