import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

a,b,c = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b,c):
    return pd.DataFrame(np.rec.fromarrays((a.values, b.values, c.values)).tolist(),columns=a.columns,index=a.index)

result = g(a.copy(),b.copy(), c.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
df["category"] = df.idxmin(axis=1)

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df1, df2 = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df1, df2):
    df = pd.concat([df1,df2.merge(df1[['id','city','district']], how='left', on='id')],sort=False).reset_index(drop=True)
    return df.sort_values(by=['id','date']).reset_index(drop=True)

result = g(df1.copy(),df2.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df[df.groupby(['Sp', 'Mt'])['count'].transform(max) == df['count']]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.columns[df.iloc[0,:].fillna('Nan') == df.iloc[8,:].fillna('Nan')]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist()[::-1]).to_frame(name='amount-time-tuple')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df = df.set_index(['user','someBool']).stack().reset_index(name='value').rename(columns={'level_2':'date'})
    return df[['user', 'date', 'value', 'someBool']]

df = g(df.copy())
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.index += 1
    df_out = df.stack()
    df.index -= 1
    df_out.index = df_out.index.map('{0[1]}_{0[0]}'.format)
    return df_out.to_frame().T

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    cols = list(df)[1:]
    cols = cols[::-1]
    for idx in df.index:
        s = 0
        cnt = 0
        for col in cols:
            if df.loc[idx, col] != 0:
                s += df.loc[idx, col]
                cnt += 1
            df.loc[idx, col] = s / (max(cnt, 1))
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    softmax = []
    min_max = []
    for i in range(len(df)):
        Min = np.inf
        Max = -np.inf
        exp_Sum = 0
        for j in range(len(df)):
            if df.loc[i, 'a'] == df.loc[j, 'a']:
                Min = min(Min, df.loc[j, 'b'])
                Max = max(Max, df.loc[j, 'b'])
                exp_Sum += np.exp(df.loc[j, 'b'])
        softmax.append(np.exp(df.loc[i, 'b']) / exp_Sum)
        min_max.append((df.loc[i, 'b'] - Min) / (Max - Min))
    df['softmax'] = softmax
    df['min-max'] = min_max
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.columns = np.concatenate([df.columns[0:1], df.iloc[0, 1:2], df.columns[2:]])
    df = df.iloc[1:].reset_index(drop=True)
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
df['Date'] = df['Date'].dt.strftime('%b-%Y')

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    result = df.replace('&','&', regex=True)

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

series = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(s):
    return pd.DataFrame.from_records(s.values,index=s.index).reset_index().rename(columns={'index': 'name'})

df = g(series.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    for i in df.index:
        for col in list(df):
            if type(df.loc[i, col]) == str:
                if '&' in df.loc[i, col]:
                    df.loc[i, col] = df.loc[i, col].replace('&', '&')
                    df.loc[i, col] = df.loc[i, col]+' = '+str(eval(df.loc[i, col]))
    df.replace('&', '&', regex=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    df.index = df.index.set_levels([df.index.levels[0], pd.to_datetime(df.index.levels[1])])
    df['date'] = sorted(df.index.levels[1].to_numpy())
    df=df[['date', 'x', 'y']]
    df = df.to_numpy()

    return df

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['cumsum'] = df.groupby('id')['val'].transform(pd.Series.cumsum)
    return df

df = g(df.copy())

###END SOLUTION
result=df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.set_index('Time', inplace=True)
    df_group = df.groupby(pd.Grouper(level='Time', freq='3T'))['Value'].agg('sum')
    df_group.dropna(inplace=True)
    df_group = df_group.to_frame().reset_index()
    return df_group

df = g(df.copy())
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, X = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, X):
    df['date'] = pd.to_datetime(df['date'])
    X *= 7
    filter_ids = [0]
    last_day = df.loc[0, "date"]
    for index, row in df[1:].iterrows():
        if (row["date"] - last_day).days > X:
            filter_ids.append(index)
            last_day = row["date"]
    df['date'] = df['date'].dt.strftime('%d-%b-%Y')
    return df.loc[filter_ids, :]

result = g(df.copy(), X)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df = df.set_index('cat')
    res = df.div(df.sum(axis=0), axis=1)
    return res.reset_index()

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df['arrival_time'] = pd.to_datetime(df['arrival_time'].replace('0', np.nan))
    df['departure_time'] = pd.to_datetime(df['departure_time'])
    df['Duration'] = df['arrival_time'] - df.groupby('id')['departure_time'].shift()
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df1 = df.groupby('Date').agg(lambda x: x.eq(0).sum())
    df2 = df.groupby('Date').agg(lambda x: x.ne(0).sum())
    return df1, df2

result1, result2 = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump((result1, result2), f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist())

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

dict, df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(dict, df):
    df["Date"] = df["Member"].apply(lambda x: dict.get(x)).fillna(np.NAN)
    for i in range(len(df)):
        if df.loc[i, 'Member'] not in dict.keys():
            df.loc[i, 'Date'] = '17/8/1926'
    return df

df = g(dict.copy(),df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.mask(~(df == df.min()).cumsum().astype(bool)).idxmax()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df = df.codes.apply(pd.Series)
    cols = list(df)
    for i in range(len(cols)):
        cols[i]+=1
    df.columns = cols
    return df.add_prefix('code_')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df['state'] = np.where((df['col2'] > 50) & (df['col3'] > 50), df['col1'], df[['col1', 'col2', 'col3']].sum(axis=1))
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.index = df.index.set_levels([df.index.levels[0], pd.to_datetime(df.index.levels[1])])
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, filter_list = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, filter_list):
    return df.query("Category == @filter_list")

result = g(df.copy(), filter_list)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('l')['v'].apply(pd.Series.sum,skipna=False)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import math
def g(df):
    return df.join(df.apply(lambda x: 1/x).add_prefix('inv_')).replace(math.inf, 0)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.mask((df == df.min()).cumsum().astype(bool))[::-1].idxmax()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.loc[(df.sum(axis=1) != 0), (df.sum(axis=0) != 0)]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby(df.index // 3).mean()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.sort_index(level='time')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    l = int(0.2 * len(df))
    dfupdate = df.sample(l, random_state=0)
    dfupdate.ProductId = 0
    df.update(dfupdate)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df = df.set_index('cat')
    res = df.div(df.sum(axis=1), axis=0)
    return res.reset_index()

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

C, D = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(C, D):
    return pd.concat([C,D]).drop_duplicates('A', keep='first').sort_values(by=['A']).reset_index(drop=True)

result = g(C.copy(),D.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.codes.apply(pd.Series).add_prefix('code_')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.DataFrame(df.row.str.split(' ',1).tolist(), columns = ['fips','row'])

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    for i in df.index:
        df.loc[i, 'col1'] = df.loc[i, 'col1'][::-1]
    L = df.col1.sum()
    L = map(lambda x:str(x), L)
    return ','.join(L)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.dt = pd.to_datetime(df.dt)
    result = df.set_index(['dt', 'user']).unstack(fill_value=-11414).asfreq('D', fill_value=-11414)
    for col in result.columns:
        Max = result[col].max()
        for idx in result.index:
            if result.loc[idx, col] == -11414:
                result.loc[idx, col] = Max
    result = result.stack().sort_index(level=1).reset_index()
    result['dt'] = result['dt'].dt.strftime('%d-%b-%Y')
    return result

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df1, df2, columns_check_list = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df1, df2, columns_check_list):
    mask= (df1[columns_check_list] == df2[columns_check_list]).any(axis=1).values
    return mask

result = g(df1, df2, columns_check_list)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def get_relation(df, col1, col2):
    first_max = df[[col1, col2]].groupby(col1).count().max()[0]
    second_max = df[[col1, col2]].groupby(col2).count().max()[0]
    if first_max==1:
        if second_max==1:
            return 'one-2-one'
        else:
            return 'one-2-many'
    else:
        if second_max==1:
            return 'many-2-one'
        else:
            return 'many-2-many'

from itertools import product
def g(df):
    result = []
    for col_i, col_j in product(df.columns, df.columns):
        if col_i == col_j:
            continue
        result.append(col_i+' '+col_j+' '+get_relation(df, col_i, col_j))
    return result

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df[df.groupby(['Sp', 'Mt'])['count'].transform(max) == df['count']]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    df['index_original'] = df.groupby(['col1', 'col2']).col1.transform('idxmin')
    result = df[df.duplicated(subset=['col1', 'col2'], keep='first')]

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, list_of_my_columns = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, list_of_my_columns):
    df['Avg'] = df[list_of_my_columns].mean(axis=1)
    df['Min'] = df[list_of_my_columns].min(axis=1)
    df['Max'] = df[list_of_my_columns].max(axis=1)
    df['Median'] = df[list_of_my_columns].median(axis=1)
    return df

df = g(df.copy(),list_of_my_columns.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['cummax'] = df.groupby('id')['val'].transform(pd.Series.cummax)
    return df

df = g(df.copy())

###END SOLUTION
result=df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.loc[~df['Field1'].astype(str).str.isdigit(), 'Field1'].tolist()

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['datetime'] = df['datetime'].dt.tz_localize(None)
    df.sort_values(by='datetime', inplace=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, filt = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, filt):
    df = df[filt[df.index.get_level_values('a')].values]
    return df[filt[df.index.get_level_values('b')].values]

result = g(df.copy(), filt.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    for col in df.columns:
        vc = df[col].value_counts()
        if col == 'Qu1':
            df[col] = df[col].apply(lambda x: x if vc[x] >= 3 or x == 'apple' else 'other')
        else:
            df[col] = df[col].apply(lambda x: x if vc[x] >= 2 or x == 'apple' else 'other')
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['cumsum'] = df.groupby('id')['val'].transform(pd.Series.cumsum)
    df['cumsum'] = df['cumsum'].where(df['cumsum'] > 0, 0)
    return df

df = g(df.copy())

###END SOLUTION
result=df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby((df.index+(-df.size % 3)) // 3).mean()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.set_index('Time', inplace=True)
    df_group = df.groupby(pd.Grouper(level='Time', freq='2T'))['Value'].agg('mean')
    df_group.dropna(inplace=True)
    df_group = df_group.to_frame().reset_index()
    return df_group

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.dt = pd.to_datetime(df.dt)
    return df.set_index(['dt', 'user']).unstack(fill_value=0).asfreq('D', fill_value=0).stack().sort_index(level=1).reset_index()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, X = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, X):
    t = df['date']
    df['date'] = pd.to_datetime(df['date'])
    filter_ids = [0]
    last_day = df.loc[0, "date"]
    for index, row in df[1:].iterrows():
        if (row["date"] - last_day).days > X:
            filter_ids.append(index)
            last_day = row["date"]
    df['date'] = t
    return df.loc[filter_ids, :]

result = g(df.copy(), X)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['ID'] = df["name"].map(str) +"-"+ df["a"].map(str)
    cnt = 0
    F = {}
    for i in range(len(df)):
        if df['ID'].iloc[i] not in F.keys():
            cnt += 1
            F[df['ID'].iloc[i]] = cnt
        df.loc[i,'ID'] = F[df.loc[i,'ID']]
    del df['name']
    del df['a']
    df = df[['ID', 'b', 'c']]
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    l = []
    for i in range(2*(len(df) // 5) + (len(df) % 5) // 3 + 1):
        l.append(0)
    for i in range(len(df)):
        idx = 2*(i // 5) + (i % 5) // 3
        if i % 5 < 3:
            l[idx] += df['col1'].iloc[i]
        elif i % 5 == 3:
            l[idx] = df['col1'].iloc[i]
        else:
            l[idx] = (l[idx] + df['col1'].iloc[i]) / 2
    return pd.DataFrame({'col1': l})

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    mask = (df.filter(like='Value').abs() > 1).any(axis=1)
    cols = {}
    for col in list(df.filter(like='Value')):
        cols[col]=col.replace("Value_","")
    df.rename(columns=cols, inplace=True)
    return df[mask]

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df['state'] = np.where((df['col2'] <= 50) & (df['col3'] <= 50), df['col1'], df[['col1', 'col2', 'col3']].max(axis=1))
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('cokey').apply(pd.DataFrame.sort_values, 'A', ascending=False)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def get_relation(df, col1, col2):
    first_max = df[[col1, col2]].groupby(col1).count().max()[0]
    second_max = df[[col1, col2]].groupby(col2).count().max()[0]
    if first_max==1:
        if second_max==1:
            return 'one-to-one'
        else:
            return 'one-to-many'
    else:
        if second_max==1:
            return 'many-to-one'
        else:
            return 'many-to-many'

from itertools import product
def g(df):
    result = []
    for col_i, col_j in product(df.columns, df.columns):
        if col_i == col_j:
            continue
        result.append(col_i+' '+col_j+' '+get_relation(df, col_i, col_j))
    return result

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, thresh = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, thresh):
    return (df[lambda x: x['value'] <= thresh]
            .append(df[lambda x: x['value'] > thresh].mean().rename('X')))

result = g(df.copy(),thresh)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.pivot_table(df, values=['D','E'], index=['B'], aggfunc={'D':np.sum, 'E':np.mean})

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    df[['number','time']] = df.duration.str.extract(r'(\d+)\s*(.*)', expand=True)
    df['time_days'] = df['time'].replace(['year', 'month', 'week', 'day'], [365, 30, 7, 1], regex=True)
    result = df

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df_a, df_b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df_a, df_b):
    return df_a[['EntityNum', 'foo']].merge(df_b[['EntityNum', 'b_col']], on='EntityNum', how='left')

result = g(df_a.copy(), df_b.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.add_prefix('X')

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, section_left, section_right = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, section_left, section_right):
    return (df[lambda x: x['value'].between(section_left, section_right)]
            .append(df[lambda x: ~x['value'].between(section_left, section_right)].mean().rename('X')))

result = g(df.copy(),section_left, section_right)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df1, df2 = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df1, df2):
    return pd.merge_asof(df2, df1, on='Timestamp', direction='forward')

result = g(df1.copy(), df2.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    cols = list(df.filter(like='col'))
    df['index_original'] = df.groupby(cols)[cols[0]].transform('idxmax')
    for i in range(len(df)):
        i = len(df) - 1 - i
        origin = df.loc[i, 'index_original']
        if i <= origin:
            continue
        if origin == df.loc[origin, 'index_original']:
            df.loc[origin, 'index_original'] = i
        df.loc[i, 'index_original'] = df.loc[origin, 'index_original']
    return df[df.duplicated(subset=cols, keep='last')]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.join(pd.DataFrame(df.var2.str.split('-', expand=True).stack().reset_index(level=1, drop=True),columns=['var2 '])).\
        drop('var2',1).rename(columns=str.strip).reset_index(drop=True)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    l = []
    for i in range(2*(len(df) // 5) + (len(df) % 5) // 3 + 1):
        l.append(0)
    for i in reversed(range(len(df))):
        idx = 2*((len(df)-1-i) // 5) + ((len(df)-1-i) % 5) // 3
        if (len(df)-1-i) % 5 < 3:
            l[idx] += df['col1'].iloc[i]
        elif (len(df)-1-i) % 5 == 3:
            l[idx] = df['col1'].iloc[i]
        else:
            l[idx] = (l[idx] + df['col1'].iloc[i]) / 2
    return pd.DataFrame({'col1': l})

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df[df.groupby(['Sp', 'Mt'])['count'].transform(max) == df['count']]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.columns = np.concatenate([df.iloc[0, :2], df.columns[2:]])
    df = df.iloc[1:].reset_index(drop=True)
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df["new"] = df.apply(lambda p: sum( not q.isalpha() for q in p["str"] ), axis=1)
    df["new"] = df["new"].replace(0, np.NAN)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df = df.set_index(['user','someBool']).stack().reset_index(name='value').rename(columns={'level_2':'date'})
    return df[['user', 'date', 'value', 'someBool']]
df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    idx = df['Column_x'].index[df['Column_x'].isnull()]
    total_nan_len = len(idx)
    first_nan = total_nan_len // 2
    df.loc[idx[0:first_nan], 'Column_x'] = 0
    df.loc[idx[first_nan:total_nan_len], 'Column_x'] = 1
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    for i in df.index:
        if str(df.loc[i, 'dogs']) != '<NA>' and str(df.loc[i, 'cats']) != '<NA>':
            df.loc[i, 'dogs'] = round(df.loc[i, 'dogs'], 2)
            df.loc[i, 'cats'] = round(df.loc[i, 'cats'], 2)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    F = {}
    cnt = 0
    for i in range(len(df)):
        if df['name'].iloc[i] not in F.keys():
            cnt += 1
            F[df['name'].iloc[i]] = cnt
        df.loc[i,'name'] = F[df.loc[i,'name']]
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['cumsum'] = df.groupby('id')['val'].transform(pd.Series.cumsum)
    return df

df = g(df.copy())

###END SOLUTION
result=df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, bins = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, bins):
    groups = df.groupby(['username', pd.cut(df.views, bins)])
    return groups.size().unstack()

result = g(df.copy(),bins.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    result = []
    for i in range(len(df)):
        if type(df.loc[i, 'A']) == str:
            result.append(i)
    return df.iloc[result]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import math
def g(df):
    return df.join(df.apply(lambda x: 1/(1+math.e**(-x))).add_prefix('sigmoid_'))

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import math
def g(df):
    return df.join(df.apply(lambda x: math.e**x).add_prefix('exp_'))

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    mask = (df.filter(like='Value').abs() > 1).any(axis=1)
    return df[mask]

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np
import io

df, test = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
result = df.drop(test, inplace = False)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
df['#1'] = np.roll(df['#1'], shift=1)
df['#2'] = np.roll(df['#2'], shift=-1)
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.replace('&', '&', regex=True, inplace=True)
    df.replace('<', '<', regex=True, inplace=True)
    df.replace('>', '>', regex=True, inplace=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.col1.sum()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    result = pd.melt(df, value_vars=df.columns.tolist())
    cols = result.columns[:-1]
    for idx in result.index:
        t = result.loc[idx, cols]
        for i in range(len(cols)):
            result.loc[idx, cols[i]] = t[cols[-i-1]]
    return result

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, row_list, column_list = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, row_list, column_list):
    return df[column_list].iloc[row_list].mean(axis=0)

result = g(df.copy(),row_list,column_list)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.drop('var2', axis=1).join(df.var2.str.split(',', expand=True).stack().
                                        reset_index(drop=True, level=1).rename('var2'))

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['frequent'] = df.mode(axis=1)
    for i in df.index:
        df.loc[i, 'freq_count'] = (df.iloc[i]==df.loc[i, 'frequent']).sum() - 1
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    to_delete = ['2020-02-17', '2020-02-18']
    df = df[~(df.index.strftime('%Y-%m-%d').isin(to_delete))]
    df.index = df.index.strftime('%d-%b-%Y %A')
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df, columns):
    ### BEGIN SOLUTION
    result = df.loc[df['c']>0.5,columns]

    return result

    ### END SOLUTION

df, columns = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df, columns)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df[['number','time']] = df.duration.str.extract(r'(\d+)\s*(.*)', expand=True)
    df['time_days'] = df['time'].replace(['year', 'month', 'week', 'day'], [365, 30, 7, 1], regex=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    return df.groupby("a")["b"].agg([np.mean, np.std])

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
df['Date'] = df['Date'].dt.strftime('%d-%b-%Y')

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    cols = list(df)[:2]+list(df)[-1:1:-1]
    df = df.loc[:, cols]
    return df.set_index(['Country', 'Variable']).rename_axis(['year'], axis=1).stack().unstack('Variable').reset_index()

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df1, df2, columns_check_list = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df1, df2, columns_check_list):
    mask= (df1[columns_check_list] != df2[columns_check_list]).any(axis=1).values
    return mask

result = g(df1, df2, columns_check_list)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df1 = df.groupby('Date').agg(lambda x: (x%2==0).sum())
    df2 = df.groupby('Date').agg(lambda x: (x%2==1).sum())
    return df1, df2

result1, result2 = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump((result1, result2), f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df[df.groupby(['Sp', 'Mt'])['count'].transform(min) == df['count']]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    if len(df.columns) == 1:
        if df.values.size == 1: return df.values[0][0]
        return df.values.squeeze()
    grouped = df.groupby(df.columns[0])
    d = {k: g(t.iloc[:, 1:]) for k, t in grouped}
    return d

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['index_original'] = df.groupby(['col1', 'col2']).col1.transform('idxmin')
    return df[df.duplicated(subset=['col1', 'col2'], keep='first')]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.loc[df.groupby("item")["diff"].idxmin()]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
df['#1'] = np.roll(df['#1'], shift=-1)
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df["keywords_all"] = df.apply(lambda x: '-'.join(x.dropna()), axis=1)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(dict, df):
    ### BEGIN SOLUTION
    df["Date"] = df["Member"].apply(lambda x: dict.get(x)).fillna(np.NAN)
    result = df

    return result

    ### END SOLUTION

dict, df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(dict, df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np
import io

df, test = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(df, test):
    ### BEGIN SOLUTION
    result = df.loc[df.index.isin(test)]

    return result

    ### END SOLUTION

result = f(df,test)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.Series('-'.join(df['text'].to_list()[::-1]), name='text')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['index_original'] = df.groupby(['col1', 'col2']).col1.transform('idxmax')
    for i in range(len(df)):
        i = len(df) - 1 - i
        origin = df.loc[i, 'index_original']
        if i <= origin:
            continue
        if origin == df.loc[origin, 'index_original']:
            df.loc[origin, 'index_original'] = i
        df.loc[i, 'index_original'] = df.loc[origin, 'index_original']
    return df[df.duplicated(subset=['col1', 'col2'], keep='last')]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    sh = 0
    min_R2 = 0
    for i in range(len(df)):
        min_R2 += (df['#1'].iloc[i]-df['#2'].iloc[i])**2
    for i in range(len(df)):
        R2 = 0
        for j in range(len(df)):
            R2 += (df['#1'].iloc[j] - df['#2'].iloc[j]) ** 2
        if min_R2 > R2:
            sh = i
            min_R2 = R2
        df['#1'] = np.roll(df['#1'], shift=1)
    df['#1'] = np.roll(df['#1'], shift=sh)
    return df

df = g(df)

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
df['datetime'] = df['datetime'].dt.tz_localize(None)
df.sort_values(by='datetime', inplace=True)
df['datetime'] = df['datetime'].dt.strftime('%d-%b-%Y %T')
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.columns[df.iloc[0,:].fillna('Nan') != df.iloc[8,:].fillna('Nan')]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.DataFrame({'text': [', '.join(df['text'].str.strip('"').tolist()[::-1])]})

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    result = df.where(df.apply(lambda x: x.map(x.value_counts())) >= 2, "other")

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df,List = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
df = df[df['Date'] >= List[0]]
df = df[df['Date'] <= List[1]]
df['Date'] = df['Date'].dt.strftime('%d-%b-%Y %A')
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.index.max(), df.index.min()

max_result,min_result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump((max_result,min_result), f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import yaml
def g(df):
    df.message = df.message.replace(['\[','\]'],['{','}'], regex=True).apply(yaml.safe_load)
    df1 = pd.DataFrame(df.pop('message').values.tolist(), index=df.index)
    result = pd.concat([df, df1], axis=1)
    result = result.replace('', 'none')
    result = result.replace(np.nan, 'none')
    return result

result = g(df.copy())
###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.Series(', '.join(df['text'].to_list()), name='text')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    for i in df.index:
        df.loc[i, 'codes'] = sorted(df.loc[i, 'codes'])
    df = df.codes.apply(pd.Series)
    cols = list(df)
    for i in range(len(cols)):
        cols[i]+=1
    df.columns = cols
    return df.add_prefix('code_')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist()).to_frame(name='amount-time-tuple')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.where(df.apply(lambda x: x.map(x.value_counts())) >= 3, "other")

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, columns = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, columns):
    return df.loc[df['c']>0.5,columns]

result = g(df.copy(), columns)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.replace('&','&', regex=True)

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df["keywords_all"] = df.apply(lambda x: ','.join(x.dropna()), axis=1)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.loc[df['name'].str.split().str.len() == 2, 'last_name'] = df['name'].str.split().str[-1]
    df.loc[df['name'].str.split().str.len() == 2, 'name'] = df['name'].str.split().str[0]
    df.rename(columns={'name': 'first_name'}, inplace=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('key1')['key2'].apply(lambda x: x.str.endswith('e').sum()).reset_index(name='count')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    F = {}
    cnt = 0
    for i in range(len(df)):
        if df['a'].iloc[i] not in F.keys():
            cnt += 1
            F[df['a'].iloc[i]] = cnt
        df.loc[i, 'a'] = F[df.loc[i, 'a']]
    return df

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    df['SOURCE_NAME'] = df['SOURCE_NAME'].str.rsplit('_', 1).str.get(0)
    result = df

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    family = np.where((df['SibSp'] + df['Parch']) >= 1 , 'Has Family', 'No Family')
    return df.groupby(family)['Survived'].mean()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, row_list, column_list = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, row_list, column_list):
    result = df[column_list].iloc[row_list].sum(axis=0)
    return result.drop(result.index[result.argmax()])

result = g(df.copy(), row_list, column_list)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('r')['v'].apply(pd.Series.sum,skipna=False)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    s = ''
    for c in df.columns:
        s += "---- %s ---" % c
        s += "\n"
        s += str(df[c].value_counts())
        s += "\n"
    return s

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['A'].replace(to_replace=0, method='bfill', inplace=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return (df.columns[df.iloc[0,:].fillna('Nan') != df.iloc[8,:].fillna('Nan')]).values.tolist()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

s = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(s):
    result = s.iloc[np.lexsort([s.index, s.values])].reset_index(drop=False)
    result.columns = ['index',1]
    return result

df = g(s.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

corr = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(corr):
    corr_triu = corr.where(~np.tril(np.ones(corr.shape)).astype(bool))
    corr_triu = corr_triu.stack()
    corr_triu.name = 'Pearson Correlation Coefficient'
    corr_triu.index.names = ['Col1', 'Col2']
    return corr_triu[corr_triu > 0.3].to_frame()

result = g(corr.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.sum())

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['TIME'] = pd.to_datetime(df['TIME'])
    df['RANK'] = df.groupby('ID')['TIME'].rank(ascending=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df=df[sorted(df.columns.to_list())]
    df.columns = pd.MultiIndex.from_tuples(df.columns, names=['Caps','Middle','Lower'])
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    L = df.col1.sum()
    L = map(lambda x:str(x), L)
    return ','.join(L)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['cumsum'] = df.groupby('id')['val'].transform(pd.Series.cumsum)
    return df

df = g(df.copy())

###END SOLUTION
result=df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.query('closing_price < 99 or closing_price > 101')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(df):
    df['arrival_time'] = pd.to_datetime(df['arrival_time'].replace('0', np.nan))
    df['departure_time'] = pd.to_datetime(df['departure_time'])
    df['Duration'] = (df['arrival_time'] - df.groupby('id')['departure_time'].shift()).dt.total_seconds()
    df["arrival_time"] = df["arrival_time"].dt.strftime('%d-%b-%Y %T')
    df["departure_time"] = df["departure_time"].dt.strftime('%d-%b-%Y %T')
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['Date'] = pd.to_datetime(df['Date'], format='%d/%m/%y')
    y = df['Date'].dt.year
    m = df['Date'].dt.month

    df['Count_d'] = df.groupby('Date')['Date'].transform('size')
    df['Count_m'] = df.groupby([y, m])['Date'].transform('size')
    df['Count_y'] = df.groupby(y)['Date'].transform('size')
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.join(pd.DataFrame(df.var2.str.split(',', expand=True).stack().reset_index(level=1, drop=True),columns=['var2 '])).\
        drop('var2',1).rename(columns=str.strip).reset_index(drop=True)

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    if len(a) < len(b):
        a = a.append(pd.DataFrame(np.array([[np.nan, np.nan]*(len(b)-len(a))]), columns=a.columns), ignore_index=True)
    elif len(a) > len(b):
        b = b.append(pd.DataFrame(np.array([[np.nan, np.nan]*(len(a)-len(b))]), columns=a.columns), ignore_index=True)
    return pd.DataFrame(np.rec.fromarrays((a.values, b.values)).tolist(), columns=a.columns, index=a.index)

result = g(a.copy(),b.copy())
###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np
import io

df, test = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, test):
    return df.loc[test]

result = g(df, test)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

dict, df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(dict, df):
    df["Date"] = df["Member"].apply(lambda x: dict.get(x)).fillna(np.NAN)
    for i in range(len(df)):
        if df.loc[i, 'Member'] not in dict.keys():
            df.loc[i, 'Date'] = '17/8/1926'
    df["Date"] = pd.to_datetime(df["Date"])
    df["Date"] = df["Date"].dt.strftime('%d-%b-%Y')
    return df

df = g(dict.copy(),df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, list_of_my_columns = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, list_of_my_columns):
    df['Avg'] = df[list_of_my_columns].mean(axis=1)
    return df

df = g(df.copy(),list_of_my_columns.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df, list_of_my_columns = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df, list_of_my_columns):
    df['Sum'] = df[list_of_my_columns].sum(axis=1)
    return df

df = g(df.copy(),list_of_my_columns.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    label = []
    for i in range(len(df)-1):
        if df.loc[i, 'Close'] > df.loc[i+1, 'Close']:
            label.append(1)
        elif df.loc[i, 'Close'] == df.loc[i+1, 'Close']:
            label.append(0)
        else:
            label.append(-1)
    label.append(1)
    df['label'] = label
    df["DateTime"] = df["DateTime"].dt.strftime('%d-%b-%Y')
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.columns = pd.MultiIndex.from_tuples(df.columns, names=['Caps','Middle','Lower'])
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.query('99 <= closing_price <= 101')

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df_out = df.stack()
    df_out.index = df_out.index.map('{0[1]}_{0[0]}'.format)
    return df_out.to_frame().T

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.DataFrame(df.row.str.split(' ', 1).tolist(), columns=['fips', 'row'])

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.groupby(df.index // 4).sum()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.loc[df['name'].str.split().str.len() >= 3, 'middle_name'] = df['name'].str.split().str[1:-1]
    for i in range(len(df)):
        if len(df.loc[i, 'name'].split()) >= 3:
            l = df.loc[i, 'name'].split()[1:-1]
            s = l[0]
            for j in range(1,len(l)):
                s += ' '+l[j]
            df.loc[i, 'middle_name'] = s
    df.loc[df['name'].str.split().str.len() >= 2, 'last_name'] = df['name'].str.split().str[-1]
    df.loc[df['name'].str.split().str.len() >= 2, 'name'] = df['name'].str.split().str[0]
    df.rename(columns={'name': 'first name'}, inplace=True)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df['TIME'] = pd.to_datetime(df['TIME'])
    df['RANK'] = df.groupby('ID')['TIME'].rank(ascending=False)
    return df

df = g(df.copy())

###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df.loc[(df['drop_if_dup'] =='No') | ~df['url'].duplicated()]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return pd.Series(df['Value'].values, index=df['Date'])

ts = g(df.copy())

###END SOLUTION
result = ts

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

def f(df):
    ### BEGIN SOLUTION
    F = {}
    cnt = 0
    for i in range(len(df)):
        if df['name'].iloc[i] not in F.keys():
            cnt += 1
            F[df['name'].iloc[i]] = cnt
        df.loc[i,'name'] = F[df.loc[i,'name']]
    result = df

    return result

    ### END SOLUTION

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = f(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    return df[df.groupby(['Sp', 'Value'])['count'].transform(max) == df['count']]

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.dt = pd.to_datetime(df.dt)
    result = df.set_index(['dt', 'user']).unstack(fill_value=-11414).asfreq('D', fill_value=-11414)
    for col in result.columns:
        Max = result[col].max()
        for idx in result.index:
            if result.loc[idx, col] == -11414:
                result.loc[idx, col] = Max
    return result.stack().sort_index(level=1).reset_index()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
df['#1'] = np.roll(df['#1'], shift=1)
###END SOLUTION
result = df

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import pandas as pd
import numpy as np

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(df):
    df.dt = pd.to_datetime(df.dt)
    return df.set_index(['dt', 'user']).unstack(fill_value=233).asfreq('D', fill_value=233).stack().sort_index(level=1).reset_index()

result = g(df.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)