Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docarray/array/doc_list/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ def to_dataframe(self) -> 'pd.DataFrame':

for doc in self:
doc_dict = _dict_to_access_paths(doc.dict())
df = df.append(doc_dict, ignore_index=True)
doc_dict = {k: [v] for k, v in doc_dict.items()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do u need to convert them to list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pd.DataFrame.from_dict() expects a dict with the column names as keys, and the values have to be a list, therefore I wrap the value with a list

Copy link
Copy Markdown
Contributor Author

@anna-charlotte anna-charlotte Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this v[0] would correspond to the first row, v[1] to the second row and so on. In our case we only have v[0] since len(v) = 1

df = pd.concat([df, pd.DataFrame.from_dict(doc_dict)], ignore_index=True)

return df

Expand Down