import pandas as pd
import sqlite3
trad = pd.read_csv('RFM_TRAD_FLOW.csv', encoding='gbk')
con = sqlite3.connect(':memory:')
trad.to_sql('trad', con)
trad.head()
| transID | cumid | time | amount | type_label | type |
---|
0 | 23351 | 10006 | 27SEP09:20:10:22 | 58.0 | 特价 | Special_offer |
---|
1 | 23372 | 30031 | 27SEP09:21:33:35 | 69.0 | 特价 | Special_offer |
---|
2 | 23447 | 40102 | 28SEP09:21:12:34 | 69.0 | 特价 | Special_offer |
---|
3 | 23448 | 20173 | 28SEP09:21:12:34 | 69.0 | 特价 | Special_offer |
---|
4 | 23449 | 40017 | 28SEP09:21:13:48 | 69.0 | 特价 | Special_offer |
---|
M_query = '''select cumid, type, sum(amount) as amount
from trad
where type="Special_offer"
group by cumid'''
pd.read_sql_query(M_query, con).head()
| cumid | type | amount |
---|
0 | 10001 | Special_offer | 420.0 |
---|
1 | 10003 | Special_offer | 156.0 |
---|
2 | 10004 | Special_offer | 373.0 |
---|
3 | 10006 | Special_offer | 58.0 |
---|
4 | 10007 | Special_offer | 179.0 |
---|