Skip to content

ENH: Adding pd.from_pydantic #61513

Open
Open
@JavierLopezT

Description

@JavierLopezT

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

There are a few methods to get a pandas DataFrame from a Pydantic model, but it will be just easier and more readable to not have any intermediate step.

Feature Description

Ideally, I could do something like:

from pydantic import BaseModel
class Item(BaseModel):
item_category: str
item_name: str
purchase_price: float
suggested_retail_price: float
item_number: int
margin: float
note: Optional[str] = None

response = : list[Item]
df = pd.from_pydantic(response)

And I will get a pandas df with columns item_category, item_name, purchase_price, suggested_retail_price, item_number, margin, note and on each row, one element of the list in response

Alternative Solutions

https://stackoverflow.com/questions/61814887/how-to-convert-a-list-of-pydantic-basemodels-to-pandas-dataframe

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions