@@ -0,0 +1,2302 @@
+import pandas as pd%0Aimport numpy as np%0Afrom datetime import datetime%0A%0Adef to_platform_indep(data, platform):%0A    if platform=='android':%0A        data.drop(%5B'ios_ifa', 'ios_ifv', 'google_aid'%5D, axis=1, inplace=True)%0A%0A        # rename cols%0A        names = data.columns.tolist()%0A        names%5Bnames.index('android_id')%5D = 'id'%0A        data.columns = names%0A    elif platform=='ios':%0A        data.drop(%5B'android_id','google_aid', 'ios_ifa'%5D, axis=1, inplace=True)%0A%0A        # rename cols%0A        names = data.columns.tolist()%0A        names%5Bnames.index('ios_ifv')%5D = 'id'%0A        data.columns = names%0A    return data%0A    %0Adef timestamp_mod(timestamp, period):%0A    return (timestamp//period)*period%0A    %0A###############################################################################%0AFILENAME = 'events_android.csv'%0APLATFORM = 'android'%0APERIOD = 24*3600 # 24h%0A%0Adata = pd.read_csv(FILENAME)%0Adata.sort_values(by='event_datetime', inplace=True)%0Adata.reset_index(drop=True, inplace=True)%0A%0Adata = to_platform_indep(data, PLATFORM)%0A%0Acols = %5B'event_datetime', 'id'%5D%0Acols.extend(data%5B'event_name'%5D.unique().tolist())%0Afeatures = pd.DataFrame(columns = cols, index = %5B%5D)%0A%0Afirst_timestamp = timestamp_mod(data%5B'event_timestamp'%5D.iloc%5B0%5D, PERIOD)%0Aend_timestamp = data%5B'event_timestamp'%5D.iloc%5B-1%5D%0A%0A#%25%25 %0Afor period_starts in np.arange(first_timestamp, end_timestamp+1, PERIOD):%0A    cur_features = pd.DataFrame(columns = cols, index = %5B%5D)%0A    cur_period_data = data%5B(period_starts %3C= data%5B'event_timestamp'%5D) &%0A                           (data%5B'event_timestamp'%5D %3C period_starts + PERIOD)%5D%0A    periods_ids = cur_period_data%5B'id'%5D.unique()%0A%0A    for id in periods_ids:%0A        ids_data4period = cur_period_data%5Bcur_period_data%5B'id'%5D == id%5D%0A        events = ids_data4period%5B'event_name'%5D.value_counts()   %0A        cur_features.loc%5Blen(cur_features)%5D = events%0A    %0A    if len(cur_features) %3E 0 :%0A        date_str = cur_period_data%5B'event_datetime'%5D.iloc%5B0%5D.split(' ')%5B0%5D%0A        date = datetime.strptime(date_str,'%25Y-%25m-%25d')%0A        cur_features%5B'id'%5D = periods_ids                %0A        cur_features%5B'event_datetime'%5D = date%0A%0A    features = features.append(cur_features, ignore_index=True)%0A%0Afeatures.fillna(0, inplace=True)%0Afeatures = features.set_index(%5B'event_datetime','id'%5D)%0Afeatures.to_csv(%221.csv%22, sep=',', header=True) 

rewrite Matrix_objects-signs (some problems on dates boundaries presents)