Pandas dataframes with object oriented programming style
Project description
Pandas-Oop
(Also known as Poop), is a package that uses Pandas dataframes with object oriented programming style
Installation:
pip install pandas-oop
Some examples
from pandas_oop import models
DB_CONNECTION = models.Connection('sqlite:///pandas_oop.db')
@models.sql(table='people', con=DB_CONNECTION)
@models.Data
class People(models.DataFrame):
name = models.StringColumn(unique=True)
age = models.IntegerColumn()
money = models.FloatColumn()
insertion_date = models.DateColumn(format='%d-%m-%Y')
is_staff = models.BoolColumn(true='yes', false='no')
Now when instantiating this class, it will return a custom dataframe with all the functionalities of a Pandas dataframe and some others
people = People()
or
people = People(from_csv=DATA_FILE, delimiter=";")
or
people = People(from_sql_query='select * from people')
or
people = People(from_df=some_dataframe)
You can also save it to the database with the save() method (if the dtypes of the columns change, this will raise a ValidationError):
people.save()
You can upsert to the database and this will automatically look at the unique fields that were declared in the class
people.save(if_row_exists='update')
or
people.save(if_row_exists='ignore')
If you want to revalidate your dataframe (convert the columns dtypes to the type that was declared in the class), you can call the validate() method:
people.validate()
You can also validate from another class. For example, you can do something like this:
people = People(from_csv=DATA_FILE)
jobs = Jobs(from_sql_query='select * from jobs')
people_with_jobs = people.merge(jobs, on='name').validate(from_class=PeopleWithJobs)
This is the list of the overriten methods that return a pandas_oop custom dataframe
- 'isnull'
- 'head'
- 'abs'
- 'merge'
I will add more and more methods on this list.
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
Hashes for pandas_oop-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ea072cc066636e5af91d434acaa283059c0a66c53ff1c9b1f7300b6fc614144 |
|
MD5 | b3969aeef993855ac714d0315c37cc45 |
|
BLAKE2b-256 | 7248b92373fd56a5e6d96c68910c4187cc73d4fd3c6684ad742a7edca105bf54 |