Commit 360ccbf2 authored by 高雅喆's avatar 高雅喆

va data add y,z,uid

parent 617ff2b3
...@@ -146,14 +146,14 @@ def get_data(): ...@@ -146,14 +146,14 @@ def get_data():
print(start) print(start)
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test') db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
sql = "select e.y,e.z,e.stat_date,e.ucity_id,e.clevel1_id,e.ccity_name," \ sql = "select e.y,e.z,e.stat_date,e.ucity_id,e.clevel1_id,e.ccity_name," \
"u.device_type,u.manufacturer,u.channel,c.top,cid_time.time " \ "u.device_type,u.manufacturer,u.channel,c.top,cid_time.time,e.device_id " \
"from esmm_train_data e left join user_feature u on e.device_id = u.device_id " \ "from esmm_train_data e left join user_feature u on e.device_id = u.device_id " \
"left join cid_type_top c on e.device_id = c.device_id left join cid_time on e.cid_id = cid_time.cid_id " \ "left join cid_type_top c on e.device_id = c.device_id left join cid_time on e.cid_id = cid_time.cid_id " \
"where e.stat_date >= '{}'".format(start) "where e.stat_date >= '{}'".format(start)
df = con_sql(db, sql) df = con_sql(db, sql)
print(df.shape) print(df.shape)
df = df.rename(columns={0: "y", 1: "z", 2: "stat_date", 3: "ucity_id",4: "clevel1_id", 5: "ccity_name", df = df.rename(columns={0: "y", 1: "z", 2: "stat_date", 3: "ucity_id",4: "clevel1_id", 5: "ccity_name",
6:"device_type",7:"manufacturer",8:"channel",9:"top",10:"time"}) 6:"device_type",7:"manufacturer",8:"channel",9:"top",10:"time",11:"device_id"})
print("esmm data ok") print("esmm data ok")
print(df.head(2)) print(df.head(2))
...@@ -161,8 +161,8 @@ def get_data(): ...@@ -161,8 +161,8 @@ def get_data():
df["y"] = df["y"].astype("str") df["y"] = df["y"].astype("str")
df["z"] = df["z"].astype("str") df["z"] = df["z"].astype("str")
df["top"] = df["top"].astype("str") df["top"] = df["top"].astype("str")
df["y"] = df["stat_date"].str.cat([df["y"].values.tolist(),df["z"].values.tolist()], sep=",") df["y"] = df["stat_date"].str.cat([df["device_id"].values.tolist(),df["y"].values.tolist(),df["z"].values.tolist()], sep=",")
df = df.drop(["z","stat_date"], axis=1).fillna(0.0) df = df.drop(["z","stat_date","device_id"], axis=1).fillna(0.0)
print(df.head(2)) print(df.head(2))
features = 0 features = 0
for i in ["ucity_id","clevel1_id","ccity_name","device_type","manufacturer","channel"]: for i in ["ucity_id","clevel1_id","ccity_name","device_type","manufacturer","channel"]:
...@@ -179,10 +179,13 @@ def transform(a,validate_date): ...@@ -179,10 +179,13 @@ def transform(a,validate_date):
df = model.fit_transform(a, y="y", n=160000, processes=22) df = model.fit_transform(a, y="y", n=160000, processes=22)
df = pd.DataFrame(df) df = pd.DataFrame(df)
df["stat_date"] = df[0].apply(lambda x: x.split(",")[0]) df["stat_date"] = df[0].apply(lambda x: x.split(",")[0])
df["device_id"] = df[0].apply(lambda x: x.split(",")[1])
df["y"] = df[0].apply(lambda x: x.split(",")[2])
df["z"] = df[0].apply(lambda x: x.split(",")[3])
df["number"] = np.random.randint(1, 2147483647, df.shape[0]) df["number"] = np.random.randint(1, 2147483647, df.shape[0])
df["seq"] = list(range(df.shape[0])) df["seq"] = list(range(df.shape[0]))
df["seq"] = df["seq"].astype("str") df["seq"] = df["seq"].astype("str")
df["data"] = df[0].apply(lambda x: ",".join(x.split(",")[1:])) df["data"] = df[0].apply(lambda x: ",".join(x.split(",")[2:]))
df["data"] = df["seq"].str.cat(df["data"], sep=",") df["data"] = df["seq"].str.cat(df["data"], sep=",")
df = df.drop([0,"seq"], axis=1) df = df.drop([0,"seq"], axis=1)
print(df.head(2)) print(df.head(2))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment