text_html_output_1.png
import numpy as np # linear algebra

import pandas as pd

import numpy as np
import pandas as pd
import gc
train = pd.read_csv('../input/digital-turbine-auction-bid-price-prediction/train_data.csv')
df = pd.read_csv('../input/digital-turbine-auction-bid-price-prediction/test_data.csv')
display(df.isnull().sum())
def agg_functions(df1):
    features = ['c1', 'deviceId', 'unitDisplayType', 'bundleId']
    global train
    for x in features:
        t = train.groupby(x)['winBid'].agg(['std', 'max', 'min', 'mean', 'median', 'var', 'sem'])
        t.columns = [x + c + '_bidWin' for c in t.columns]
        t = t.astype({c: np.float32 for c in t.columns})
        t.reset_index(inplace=True)
        df1 = df1.merge(t, on=x, how='left')
        gc.collect()
    return df1
print(len(df))
df = agg_functions(df)
print(len(df))
train = agg_functions(train)
s = train.deviceIdstd_bidWin.mean()
df['deviceIdstd_bidWin'].fillna(s, inplace=True)
s = train.deviceIdmin_bidWin.mean()
df['deviceIdmin_bidWin'].fillna(s, inplace=True)
s = train.deviceIdmax_bidWin.mean()
df['deviceIdmax_bidWin'].fillna(s, inplace=True)
s = train.deviceIdmean_bidWin.mean()
df['deviceIdmean_bidWin'].fillna(s, inplace=True)
s = train.deviceIdmedian_bidWin.mean()
df['deviceIdmedian_bidWin'].fillna(s, inplace=True)
s = train.deviceIdvar_bidWin.mean()
df['deviceIdvar_bidWin'].fillna(s, inplace=True)
s = train.deviceIdsem_bidWin.mean()
df['deviceIdsem_bidWin'].fillna(s, inplace=True)
del train
gc.collect()
cols = ['unitDisplayTypemin_bidWin']
df.drop(cols, axis=1, inplace=True)
display(df.isnull().sum())