
# Pandas-Oop
(Also known as Poop), is a package that uses Pandas dataframes with object oriented programming style
Installation:
-
```shell script
pip install pandas-oop
```
Some examples
-
```python
from pandas_oop import models
from pandas_oop.fields import StringColumn, IntegerColumn, FloatColumn, DateColumn, BoolColumn
```
```python
DB_CONNECTION = models.Connection('sqlite:///pandas_oop.db') # this is the same con_string for sqlalchemy engine
```
```python
@models.sql(table='people', con=DB_CONNECTION) # Use this decorator if you want to connect your class to a database
@models.Data
class People(models.DataFrame):
name = StringColumn(unique=True)
age = IntegerColumn()
money = FloatColumn(target_name="coins") # target_name if the name in the csv or table is coins and you want to have a different variable name
insertion_date = DateColumn(format='%d-%m-%Y')
is_staff = 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
```python
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)
or
people = People(from_iterator=some_function_that_yield_values)
```
example of function that yield values:
```python
def some_function_that_yield_values():
while something:
...
yield name, age, money, insertion_date, is_staff
```

You can also save it to the database with the save() method (if the dtypes of the columns change, this will raise a
ValidationError):
```python
people.save()
```
You can upsert to the database and this will automatically look at the unique fields that were declared in the class
```python
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:
```python
people.validate()
```
You can also validate from another class. For example, you can do something like this:
```python
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'
- 'loc' and dataframe slicing
I will add more and more methods on this list.
New features
-
Alembic Database migration support added:
- On your main application package, import Base (this is a declarative_base from sqlalchemy)
```python
from pandas_oop import Base
```
- Add this configuration on the env.py file of your alembic config
```python
from your_app import Base
target_metadata = Base.metadata
```
- And finaly, update your database url on your alembic.ini file
没有合适的资源?快使用搜索试试~ 我知道了~
pandas-oop-0.9.5.tar.gz
需积分: 1 0 下载量 175 浏览量
2024-03-07
12:45:01
上传
评论
收藏 9KB GZ 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论




























收起资源包目录





















共 16 条
- 1
资源评论


程序员Chino的日记
- 粉丝: 4227
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- (2025)社工初级考试试题附含答案.docx
- (2025)社工初级考试试题含答案.docx
- 电信5G协优资格认证考试题库附含答案.docx
- 电信协优(含LTE、5G)资格认证考试题库附答案.docx
- 电信协优(含LTE、5G)资格认证考试题库附含答案.docx
- 电信协优(含LTE、5G)资格认证题库附答案.docx
- (2025)电梯安全管理员题库及答案.doc
- (2025)电业安全工作规程考试试题及答案.doc
- (2025)电业安全工作规程试题及答案.doc
- (2025)吊车司机安全培训考试题库及答案.doc
- (2025)辐射安全与防护培训考试题及答案.doc
- (2025)辐射安全与防护培训题库(含答案).doc
- (2025)辐射安全与防护培训题库及答案.doc
- 2025安全生产培训教育考试题库及答案.doc
- 2025安全生产培训教育考试试题及答案.doc
- 2025安全生产培训教育试题及答案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
