Commit 1604637c authored by 张彦钊's avatar 张彦钊

change

parent ca2a9bcc
......@@ -42,7 +42,7 @@ def ctr_all():
def get_data():
conn2db = pymysql.connect(host='172.16.40.158', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_test')
cursor = conn2db.cursor()
sql = "select cid,exp,click from diary_ctr"
sql = "select number from id_number"
cursor.execute(sql)
result = cursor.fetchall()
......@@ -55,10 +55,14 @@ if __name__ == "__main__":
DIRECTORY_PATH = "/home/gmuser/"
df = pd.DataFrame(list(get_data()))
print(df.head())
df = df.rename(columns={0:"cid",1:"exp",2:"click"})
df["click"] = df["click"].fillna(0)
df["ctr"] = df["click"]/df["exp"]
df = df.rename(columns={0:"number"})
df.to_csv(DIRECTORY_PATH+"number.csv",index=False)
yconnect = create_engine('mysql+pymysql://root:3SYz54LS9#^9sBvC@172.16.40.158:4000/jerry_test?charset=utf8')
pd.io.sql.to_sql(df, "diary_ctr_new", yconnect, schema='jerry_test', if_exists='append', index=False)
# df = df.rename(columns={0:"cid",1:"exp",2:"click"})
# df["click"] = df["click"].fillna(0)
# df["ctr"] = df["click"]/df["exp"]
#
# yconnect = create_engine('mysql+pymysql://root:3SYz54LS9#^9sBvC@172.16.40.158:4000/jerry_test?charset=utf8')
# pd.io.sql.to_sql(df, "diary_ctr_new", yconnect, schema='jerry_test', if_exists='append', index=False)
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