Commit e1c927f2 authored by 张彦钊's avatar 张彦钊

add app list

parent 9cebd53e
import pandas as pd
import pymysql
import json
from sqlalchemy import create_engine
def con_sql(db,sql):
cursor = db.cursor()
......@@ -28,7 +29,7 @@ def json_format(x):
def sort_app():
db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_prod')
sql = "select device_id,app_list from device_id_applist limit 20000"
sql = "select device_id,app_list from device_id_applist"
df = con_sql(db, sql).dropna()
df = df.rename(columns={0: "device_id", 1: "app_list"})
df = df.loc[df["app_list"].apply(is_json)]
......@@ -70,8 +71,9 @@ def sort_app():
df["app_list"] = df["app_list"].apply(json_format)
for i in category.keys():
df[i] = df["app_list"].apply(lambda x: 1 if len(x & category[i]) > 0 else 0)
print(i)
print(df[i].unique())
yconnect = create_engine('mysql+pymysql://root:3SYz54LS9#^9sBvC@10.66.157.22:4000/jerry_test?charset=utf8')
pd.io.sql.to_sql(df, "app_list_sort", yconnect, schema='jerry_test', if_exists='replace', index=False)
if __name__ == "__main__":
......
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