Library for converting pandas dataframes to pydantic models
Project description
pandas-to-pydantic
Library for converting pandas dataframes into pydantic models
Table of Contents
Installation
pip install pandas-to-pydantic
Example
Using this example test data
import pandas as pd
from pydantic import BaseModel
from pandas_to_pydantic import dataframeToPydantic
# Declare pydantic models
class Book(BaseModel):
BookID: int
Title: str
Genre: str
PublishedYear: int
AvailableCopies: int
class Author(BaseModel):
AuthorID: int
AuthorName: str
AuthorBirthdate: str
BookList: list[Book]
class Library(BaseModel):
LibraryID: int
LibraryName: str
Location: str
EstablishedYear: int
BookCollectionSize: int
AuthorList: list[Author]
# Input data is a pandas dataframe
data = pd.read_csv(FILE_PATH)
# Convert pandas dataframe to a pydantic root model
libraryListRoot = dataframeToPydantic(data, Library)
# Access data as a list of pydantic models
libraryListRoot.root
# Access data as a list of dict
libraryListRoot.model_dump()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pandas_to_pydantic-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fa7f9178b082f0ef83f29e6b81b90069427463a8ff9a9ceb9572b749a08adf5 |
|
MD5 | c831fc4bdd13442bca8b696ec717e929 |
|
BLAKE2b-256 | 6f9228bccf25ed0253f1327d9e59915461ef08b84f5de45d809b2a3746fcf7e7 |