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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pandas_to_pydantic-0.0.3.tar.gz.
File metadata
- Download URL: pandas_to_pydantic-0.0.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.25.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c8efe08c5e94d258f4827ba80a0670baa165258a906e76118324c13ab1192a0
|
|
| MD5 |
05cee4b4c7b3048c2afe79600efdbd1c
|
|
| BLAKE2b-256 |
556c7230bbe4be9d191798a259f194958e68463a410d6341a327f9ae5dcdfc06
|
File details
Details for the file pandas_to_pydantic-0.0.3-py3-none-any.whl.
File metadata
- Download URL: pandas_to_pydantic-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.25.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fa7f9178b082f0ef83f29e6b81b90069427463a8ff9a9ceb9572b749a08adf5
|
|
| MD5 |
c831fc4bdd13442bca8b696ec717e929
|
|
| BLAKE2b-256 |
6f9228bccf25ed0253f1327d9e59915461ef08b84f5de45d809b2a3746fcf7e7
|