Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
1604637c
Commit
1604637c
authored
Oct 25, 2019
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
ca2a9bcc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
ctr_exp.py
ctr_exp.py
+10
-6
No files found.
ctr_exp.py
View file @
1604637c
...
@@ -42,7 +42,7 @@ def ctr_all():
...
@@ -42,7 +42,7 @@ def ctr_all():
def
get_data
():
def
get_data
():
conn2db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
conn2db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
cursor
=
conn2db
.
cursor
()
cursor
=
conn2db
.
cursor
()
sql
=
"select
cid,exp,click from diary_ct
r"
sql
=
"select
number from id_numbe
r"
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
result
=
cursor
.
fetchall
()
...
@@ -55,10 +55,14 @@ if __name__ == "__main__":
...
@@ -55,10 +55,14 @@ if __name__ == "__main__":
DIRECTORY_PATH
=
"/home/gmuser/"
DIRECTORY_PATH
=
"/home/gmuser/"
df
=
pd
.
DataFrame
(
list
(
get_data
()))
df
=
pd
.
DataFrame
(
list
(
get_data
()))
print
(
df
.
head
())
print
(
df
.
head
())
df
=
df
.
rename
(
columns
=
{
0
:
"cid"
,
1
:
"exp"
,
2
:
"click"
})
df
=
df
.
rename
(
columns
=
{
0
:
"number"
})
df
[
"click"
]
=
df
[
"click"
]
.
fillna
(
0
)
df
.
to_csv
(
DIRECTORY_PATH
+
"number.csv"
,
index
=
False
)
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
)
# 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)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment