38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
from sqlalchemy import create_engine
|
|
|
|
engine = create_engine("mysql+pymysql://root:123456@localhost/lottery?charset=utf8")
|
|
conn = engine.connect()
|
|
sql = """SELECT
|
|
id, sum_num, (id - MAX(last_id)) AS span
|
|
FROM (
|
|
SELECT
|
|
p.id, t1.id AS last_id, p.sum_num
|
|
FROM pls p
|
|
LEFT JOIN (
|
|
SELECT id, sum_num
|
|
FROM pls ORDER BY id
|
|
) t1 ON t1.sum_num = p.sum_num AND t1.id < p.id
|
|
) tmp GROUP BY id, sum_num"""
|
|
df = pd.read_sql(sql, conn)
|
|
print(df.loc[["sum_num", "span"]][:30])
|
|
|
|
# s1 = pd.Series([1.47, 2.3, 3.0])
|
|
# s2 = pd.Series([5.5, 6.1])
|
|
# s3 = pd.Series([2.3, 4.6, 5.3])
|
|
|
|
# s1.index = [True, False, False]
|
|
# s2.index = [False, True]
|
|
# s3.index = [False, True, False]
|
|
|
|
# a1 = np.expand_dims(s1.to_numpy(), axis=0)
|
|
# a2 = np.expand_dims(s2.to_numpy(), axis=0)
|
|
# a3 = np.expand_dims(s3.to_numpy(), axis=0)
|
|
|
|
# print(a1.shape)
|
|
# print(a2.T.shape)
|
|
# print((a1.T)*a2)
|
|
# t = (a2.T)*a1
|
|
# print(len(t.flatten()))
|
|
# print((s1*s2).loc[True]) |