Feature Type
-
[x] 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
Comment From: kernelism
take