-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-bid-calc.py
35 lines (25 loc) · 873 Bytes
/
base-bid-calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pandas as pd
from pandas import DataFrame
import numpy as np
import csv
#read data file, must have "ACTR" & "PCTR as columns
df = pd.read_csv("logisticregressionpctrdata.csv")
dict1 = dict()
for x in range(10, 301, 10): #set base bid range
df['bid'] = df.apply(lambda row: (x) * (row['PCTR'] / row['ACTR']), axis=1)
df2 = df[(df.bid > df.payprice)]
base_bid = x
ctr = df2['click'].sum().astype('float64') / df2['logtype'].sum().astype('float64')
print "Base Bid:", x
print "CTR:", ctr
dict2 = {x: ctr}
dict1.update(dict2)
print "BEST BID VALUE BELOW"
print max(dict1, key=dict1.get)
data = pd.DataFrame.from_dict(dict1, orient="index")
#SET OUTPUT CSV NAME
data.to_csv("test3.csv")
#CONFIRM OUTPUT CSV NAME
dataframe = pd.read_csv("test3.csv", index_col=0)
d = dataframe.to_dict("split")
d = dict(zip(d["index"], d["data"]))