Update dataframe.py (#28871)

community: optimize DataFrame document loader

**Description:**
Simplify the `lazy_load` method in the DataFrame document loader by
combining text extraction and metadata cleanup into a single operation.
This makes the code more concise while maintaining the same
functionality.

**Issue:** N/A

**Dependencies:** None

**Twitter handle:** N/A
This commit is contained in:
Darien Schettler 2024-12-22 19:16:16 -05:00 committed by GitHub
parent cb4e6ac941
commit 32917a0b98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,9 +21,8 @@ class BaseDataFrameLoader(BaseLoader):
"""Lazy load records from dataframe.""" """Lazy load records from dataframe."""
for _, row in self.data_frame.iterrows(): for _, row in self.data_frame.iterrows():
text = row[self.page_content_column]
metadata = row.to_dict() metadata = row.to_dict()
metadata.pop(self.page_content_column) text = metadata.pop(self.page_content_column)
yield Document(page_content=text, metadata=metadata) yield Document(page_content=text, metadata=metadata)