|
1 | | - |
2 | | -Pandas dataframes with object oriented programming style |
| 1 | + |
| 2 | +# Pandas-Oop |
| 3 | +(Also known as Poop), is a package that uses Pandas dataframes with object oriented programming style |
3 | 4 |
|
4 | 5 | Installation: |
5 | 6 | - |
6 | 7 |
|
7 | 8 | ```shell script |
8 | 9 | pip install pandas-oop |
9 | 10 | ``` |
| 11 | +Some examples |
| 12 | +- |
10 | 13 |
|
| 14 | +```python |
| 15 | +from pandas_oop import models |
| 16 | +``` |
| 17 | + |
| 18 | +```python |
| 19 | +@models.sql(table='people', con=DB_CONNECTION) |
| 20 | +@models.Data |
| 21 | +class People(models.DataFrame): |
| 22 | + name = models.StringColumn() |
| 23 | + age = models.IntegerColumn() |
| 24 | + money = models.FloatColumn() |
| 25 | + insertion_date = models.DateColumn(format='%d-%m-%Y') |
| 26 | + is_staff = models.BoolColumn(true='yes', false='no') |
| 27 | +``` |
| 28 | + |
| 29 | +Now when instantiating this class, it will return a custom dataframe with all the functionalities of a Pandas |
| 30 | +dataframe and some others |
| 31 | + |
| 32 | +```python |
| 33 | +people = People() |
| 34 | +or |
| 35 | +people = People(from_csv=DATA_FILE, delimiter=";") |
| 36 | +or |
| 37 | +people = People(from_sql_query='select * from people') |
| 38 | +``` |
| 39 | + |
| 40 | +You can also save it to the database with the save() method (if the dtypes of the columns change, this will raise a |
| 41 | +ValidationException): |
| 42 | + |
| 43 | +```python |
| 44 | +people.save(if_exists='append', index=False) |
| 45 | +``` |
| 46 | + |
| 47 | +If you want to revalidate your dataframe (convert the columns dtypes to the type that was declared in the class), you can |
| 48 | +call the validate() method: |
| 49 | + |
| 50 | +```python |
| 51 | +people.validate() |
| 52 | +``` |
| 53 | +Coming soon |
| 54 | +- |
| 55 | +functions that are supported on the major databases (sqlite, postgres, oracle, mysql) |
| 56 | +- save or update on duplicate |
| 57 | +- save or do nothing on duplicate |
0 commit comments