python python_dataframes_sql.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python_dataframes_sql.py相关的知识,希望对你有一定的参考价值。
import pandas as pd
import pandasql as pdsql
pysql = lambda q: pdsql.sqldf(q, globals())
orders = pd.read_csv('/Users/itversity/Research/data/retail_db/orders/part-00000',
names=['order_id', 'order_date', 'order_customer_id', 'order_status'],
index_col='order_id')
order_items = pd.read_csv('/Users/itversity/Research/data/retail_db/order_items/part-00000',
names=['order_item_id', 'order_item_order_id', 'order_item_product_id',
'order_item_quantity', 'order_item_subtotal', 'order_item_product_price'],
index_col='order_item_order_id')
revenue_per_day_sql = """select o.order_date, sum(oi.order_item_subtotal) daily_revenue
from orders o join order_items oi on o.order_id = oi.order_item_order_id
where o.order_status in ('COMPLETE', 'CLOSED')
group by o.order_date
order by o.order_date"""
revenue_per_day = pysql(revenue_per_day_sql)
以上是关于python python_dataframes_sql.py的主要内容,如果未能解决你的问题,请参考以下文章
python中__call__方法解析
python中的__name__
求一道python编程题
Python __name__ == ‘__main__’详细解释-Python零基础入门教程
Python __dict__与dir()区别
Python零碎