dwadaw

wadwadwadwa
mail@pastecode.io avatar
unknown
python
a year ago
959 B
7
Indexable
Never
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.model_selection import train_test_split
import ast

inter_train = pd.read_csv('inter_train.csv')
visitors = pd.read_csv('visitors.csv')


for i in range(58):
    inter_train[f'interest{i}'] = 0

processed_u = set()

for index, row in inter_train.iterrows():
    if row['u'] in processed_u:
        continue
    match = visitors[visitors['u'] == row['u']]
    #if match
    if not match.empty:
        interests = match['interests'].values[0]
        interests = [int(i) for i in interests.strip("[]").split(",")]
        for i, interest in enumerate(interests):
            #conditie voor vervangen met 0 of 1
            inter_train.at[index, f'interest{i}'] = 1 if interest > 0 else 0
    processed_u.add(row['u'])
print(inter_train.head())