def g(data):
    unique_groups = np.unique(data['group'])
    result = []
    for group in unique_groups:
        mask = data['group'] == group
        group_data = data[mask]
        group_color = group_data['group_color'][0]
        sums = tuple(group_data[name].sum() for name in data.dtype.names if name.startswith('val'))
        result.append((group, group_color) + sums)
    return np.array(result, dtype=[('group', 'U1'), ('group_color', 'U5')] + [(name, 'i4') for name in data.dtype.names if name.startswith('val')])

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_groups = np.unique(data['group'])
        result = []
        for group in unique_groups:
            mask = data['group'] == group
            group_data = data[mask]
            group_color = group_data['group_color'][0]
            sums = tuple(group_data[name].sum() for name in data.dtype.names if name.startswith('val'))
            result.append((group, group_color) + sums)
        return np.array(result, dtype=[('group', 'U1'), ('group_color', 'U5')] + [(name, 'i4') for name in data.dtype.names if name.startswith('val')])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            dtype = [('group', 'U1'), ('group_color', 'U5'), ('val1', 'i4'), ('val2', 'i4'), ('val3', 'i4')]
            data = np.array([
                ('A', 'green', 5, 4, 1),
                ('A', 'green', 2, 2, 1),
                ('A', 'green', 3, 8, 4),
                ('B', 'blue', 4, 5, 5),
                ('B', 'blue', 5, 7, 1)
            ], dtype=dtype)
        return data

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.sum())

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.groupby("group").agg(
            lambda x: x.head(1) if x.dtype == "object" else x.sum()
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "group": ["A", "A", "A", "B", "B"],
                    "group_color": ["green", "green", "green", "blue", "blue"],
                    "val1": [5, 2, 3, 4, 5],
                    "val2": [4, 2, 8, 5, 7],
                    "val3": [1, 1, 4, 5, 1],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

data = np.array([[34, 'null', 'null'], [22, 'null', 'mark'], [34, 'null', 'mark']])

result = ... # put solution in this variable

def g(data):
    counts = np.apply_along_axis(lambda x: np.sum(x == 'null'), axis=0, arr=data)
    return counts.astype(float)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        counts = np.apply_along_axis(lambda x: np.sum(x == 'null'), axis=0, arr=data)
        return counts.astype(float)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [34, 'null', 'null'],
                [22, 'null', 'mark'],
                [34, 'null', 'mark']
            ])
        if test_case_id == 2:
            data = np.array([
                [34, 'null', 'null'],
                [22, 'null', 'mark'],
                [34, 'null', 'null']
            ])
        return data

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

df = pd.DataFrame({'id': [34, 22, 34], 'temp': [null, null, null], 'name': [null, 'mark', 'mark']})

import pandas as pd

df = pd.DataFrame(data=[[34, 'null', 'null'], [22, 'null', 'mark'], [34, 'null', 'mark']], columns=['id', 'temp', 'name'], index=[1, 2, 3])

result = ... # put solution in this variable

def g(df):
    return df.astype(str).apply(lambda x: x.value_counts()).T['null']

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.astype(str).apply(lambda x: x.value_counts()).T['null']

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[[34, "null", "null"], [22, "null", "mark"], [34, "null", "mark"]],
                columns=["id", "temp", "name"],
                index=[1, 2, 3],
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                data=[[34, "null", "null"], [22, "null", "mark"], [34, "null", "null"]],
                columns=["id", "temp", "name"],
                index=[1, 2, 3],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_series_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([[34, 'null', 'mark'], [22, 'null', 'mark'], [34, 'null', 'mark']])

result = ... # put solution in this variable

def g(arr):
    s = ''
    for i, col in enumerate(arr.T):
        s += "---- %s ---" % i
        s += "\n"
        unique, counts = np.unique(col, return_counts=True)
        for val, count in zip(unique, counts):
            s += f"{val}    {count}\n"
    return s

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        s = ""
        for i, col in enumerate(arr.T):
            s += "---- %s ---" % i
            s += "\n"
            unique, counts = np.unique(col, return_counts=True)
            for val, count in zip(unique, counts):
                s += f"{val}    {count}\n"
        return s

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(
                [[34, "null", "mark"], [22, "null", "mark"], [34, "null", "mark"]]
            )
        elif test_case_id == 2:
            arr = np.array(
                [[11, "null", "mark"], [14, "null", "mark"], [51, "null", "mark"]]
            )
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

id, temp, name
1 34, null, mark
2 22, null, mark
3 34, null, mark

import pandas as pd

df = pd.DataFrame(data=[[34, 'null', 'mark'], [22, 'null', 'mark'], [34, 'null', 'mark']], columns=['id', 'temp', 'name'], index=[1, 2, 3])

result = ... # put solution in this variable

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        s = ""
        for c in df.columns:
            s += "---- %s ---" % c
            s += "\n"
            s += str(df[c].value_counts())
            s += "\n"
        return s

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[[34, "null", "mark"], [22, "null", "mark"], [34, "null", "mark"]],
                columns=["id", "temp", "name"],
                index=[1, 2, 3],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                data=[[11, "null", "mark"], [14, "null", "mark"], [51, "null", "mark"]],
                columns=["id", "temp", "name"],
                index=[1, 2, 3],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([[3, 1, 2], [np.nan, 1, 2], [np.nan, np.nan, 2]])

result = ... # put solution in this variable

def justify(a, invalid_val=np.nan, axis=1, side='left'):
    if invalid_val is np.nan:
        mask = ~np.isnan(a)
    else:
        mask = a != invalid_val
    justified_mask = np.sort(mask, axis=axis)
    if (side == 'up') | (side == 'left'):
        justified_mask = np.flip(justified_mask, axis=axis)
    out = np.full(a.shape, invalid_val)
    if axis == 1:
        out[justified_mask] = a[mask]
    else:
        out.T[justified_mask.T] = a.T[mask.T]
    return out

result = justify(arr, invalid_val=np.nan, axis=1, side='left')

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data

        def justify(a, invalid_val=np.nan, axis=1, side='left'):
            if invalid_val is np.nan:
                mask = ~np.isnan(a)
            else:
                mask = a != invalid_val
            justified_mask = np.sort(mask, axis=axis)
            if (side == 'up') | (side == 'left'):
                justified_mask = np.flip(justified_mask, axis=axis)
            out = np.full(a.shape, invalid_val)
            if axis == 1:
                out[justified_mask] = a[mask]
            else:
                out.T[justified_mask.T] = a.T[mask.T]
            return out

        return justify(arr, invalid_val=np.nan, axis=1, side='left')

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(
                [[3, 1, 2], [np.nan, 1, 2], [np.nan, np.nan, 2]]
            )
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    assert 'for' not in solution and 'while' not in solution and 'apply_along_axis' not in solution

import pandas as pd
import numpy as np

df = pd.DataFrame([[3,1,2],[np.nan,1,2],[np.nan,np.nan,2]],columns=['0','1','2'])

result = ... # put solution in this variable

def justify(a, invalid_val=0, axis=1, side='left'):
    if invalid_val is np.nan:
        mask = ~np.isnan(a)
    else:
        mask = a!=invalid_val
    justified_mask = np.sort(mask,axis=axis)
    if (side=='up') | (side=='left'):
        justified_mask = np.flip(justified_mask,axis=axis)
    out = np.full(a.shape, invalid_val)
    if axis==1:
        out[justified_mask] = a[mask]
    else:
        out.T[justified_mask.T] = a.T[mask.T]
    return out

def g(df):
    return pd.DataFrame(justify(df.values, invalid_val=np.nan, axis=1, side='left'))

result = g(df.copy())

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data

        def justify(a, invalid_val=0, axis=1, side="left"):
            if invalid_val is np.nan:
                mask = ~np.isnan(a)
            else:
                mask = a != invalid_val
            justified_mask = np.sort(mask, axis=axis)
            if (side == "up") | (side == "left"):
                justified_mask = np.flip(justified_mask, axis=axis)
            out = np.full(a.shape, invalid_val)
            if axis == 1:
                out[justified_mask] = a[mask]
            else:
                out.T[justified_mask.T] = a.T[mask.T]
            return out

        return pd.DataFrame(justify(df.values, invalid_val=np.nan, axis=1, side="left"))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                [[3, 1, 2], [np.nan, 1, 2], [np.nan, np.nan, 2]],
                columns=["0", "1", "2"],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "for" not in tokens and "while" not in tokens and "apply" not in tokens


def justify(a, invalid_val=np.nan, axis=1, side='left'):
    if np.isnan(invalid_val):
        mask = ~np.isnan(a)
    else:
        mask = a != invalid_val
    justified_mask = np.sort(mask, axis=axis)
    if (side == 'up') | (side == 'left'):
        justified_mask = np.flip(justified_mask, axis=axis)
    out = np.full(a.shape, invalid_val)
    if axis == 1:
        out[justified_mask] = a[mask]
    else:
        out.T[justified_mask.T] = a.T[mask.T]
    return out

result = justify(arr, invalid_val=np.nan, axis=0, side='down')

import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data

        def justify(a, invalid_val=np.nan, axis=1, side='left'):
            if np.isnan(invalid_val):
                mask = ~np.isnan(a)
            else:
                mask = a != invalid_val
            justified_mask = np.sort(mask, axis=axis)
            if (side == 'up') | (side == 'left'):
                justified_mask = np.flip(justified_mask, axis=axis)
            out = np.full(a.shape, invalid_val)
            if axis == 1:
                out[justified_mask] = a[mask]
            else:
                out.T[justified_mask.T] = a.T[mask.T]
            return out

        return justify(arr, invalid_val=np.nan, axis=0, side='down')

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(
                [[3, 1, 2], [np.nan, 1, 2], [np.nan, np.nan, 2]]
            )
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "for" not in tokens and "while" not in tokens and "apply" not in tokens

def justify(a, invalid_val=0, axis=1, side='left'):
    if invalid_val is np.nan:
        mask = ~np.isnan(a)
    else:
        mask = a!=invalid_val
    justified_mask = np.sort(mask,axis=axis)
    if (side=='up') | (side=='left'):
        justified_mask = np.flip(justified_mask,axis=axis)
    out = np.full(a.shape, invalid_val)
    if axis==1:
        out[justified_mask] = a[mask]
    else:
        out.T[justified_mask.T] = a.T[mask.T]
    return out

def g(df):
    return pd.DataFrame(justify(df.values, invalid_val=np.nan, axis=0, side='down'))

result = g(df.copy())

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data

        def justify(a, invalid_val=0, axis=1, side="left"):
            if invalid_val is np.nan:
                mask = ~np.isnan(a)
            else:
                mask = a != invalid_val
            justified_mask = np.sort(mask, axis=axis)
            if (side == "up") | (side == "left"):
                justified_mask = np.flip(justified_mask, axis=axis)
            out = np.full(a.shape, invalid_val)
            if axis == 1:
                out[justified_mask] = a[mask]
            else:
                out.T[justified_mask.T] = a.T[mask.T]
            return out

        return pd.DataFrame(justify(df.values, invalid_val=np.nan, axis=0, side="down"))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                [[3, 1, 2], [np.nan, 1, 2], [np.nan, np.nan, 2]],
                columns=["0", "1", "2"],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "for" not in tokens and "while" not in tokens and "apply" not in tokens


import numpy as np

values = np.array([50, 35, 8, 5, 1, 1])
labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
thresh = 6

result_values = ...  # put solution in this variable
result_labels = ...  # put solution in this variable

def g(values, labels, thresh):
    mask = values >= thresh
    new_values = np.append(values[mask], values[~mask].sum())
    new_labels = np.append(labels[mask], 'X')
    return new_values, new_labels

result_values, result_labels = g(values.copy(), labels.copy(), thresh)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        values, labels, thresh = data
        mask = values >= thresh
        new_values = np.append(values[mask], values[~mask].sum())
        new_labels = np.append(labels[mask], 'X')
        return new_values, new_labels

    def define_test_input(test_case_id):
        if test_case_id == 1:
            values = np.array([50, 35, 8, 5, 1, 1])
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            thresh = 6
        if test_case_id == 2:
            values = np.array([50, 35, 8, 5, 1, 1])
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            thresh = 9
        return values, labels, thresh

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        np.testing.assert_array_equal(result[1], ans[1])
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
values, labels, thresh = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test((test_env["result_values"], test_env["result_labels"]), expected_result)

import pandas as pd

df = pd.DataFrame({'lab':['A', 'B', 'C', 'D', 'E', 'F'], 'value':[50, 35, 8, 5, 1, 1]})
df = df.set_index('lab')
thresh = 6

result = ... # put solution in this variable

def g(df, thresh):
    return (df[lambda x: x['value'] >= thresh] ._append(df[lambda x: x['value'] < thresh].sum().rename('X')))

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, thresh = data
        return df[lambda x: x["value"] >= thresh]._append(
            df[lambda x: x["value"] < thresh].sum().rename("X")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            thresh = 6
        if test_case_id == 2:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            thresh = 9
        return df, thresh

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, thresh = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

values = np.array([50, 35, 8, 5, 1, 1])
labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
thresh = 6

result_values, result_labels = ... # put solution in these variables

def g(values, labels, thresh):
    below_thresh = values <= thresh
    above_thresh = values > thresh
    below_values = values[below_thresh]
    below_labels = labels[below_thresh]
    above_mean = np.mean(values[above_thresh])
    return np.append(below_values, above_mean), np.append(below_labels, 'X')

result_values, result_labels = g(values.copy(), labels.copy(), thresh)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        values, labels, thresh = data
        below_thresh = values <= thresh
        above_thresh = values > thresh
        below_values = values[below_thresh]
        below_labels = labels[below_thresh]
        above_mean = np.mean(values[above_thresh])
        return np.append(below_values, above_mean), np.append(below_labels, 'X')

    def define_test_input(test_case_id):
        if test_case_id == 1:
            values = np.array([50, 35, 8, 5, 1, 1])
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            thresh = 6
        if test_case_id == 2:
            values = np.array([50, 35, 8, 5, 1, 1])
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            thresh = 9
        return values, labels, thresh

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        np.testing.assert_array_equal(result[1], ans[1])
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
values, labels, thresh = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test((test_env["result_values"], test_env["result_labels"]), expected_result)

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)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, thresh = data
        return df[lambda x: x["value"] <= thresh]._append(
            df[lambda x: x["value"] > thresh].mean().rename("X")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            thresh = 6
        if test_case_id == 2:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            thresh = 9
        return df, thresh

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, thresh = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
values = np.array([50, 35, 8, 5, 1, 1])
data = np.column_stack((labels, values))
section_left = 4
section_right = 38

result = ... # put solution in this variable

def g(data, section_left, section_right):
    values = data[:, 1].astype(float)
    mask = (values >= section_left) & (values <= section_right)
    filtered_data = data[mask]
    mean_value = np.mean(values[~mask])
    aggregated_row = np.array([['X', mean_value]], dtype=object)
    return np.vstack((filtered_data, aggregated_row))

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        array, section_left, section_right = data
        values = array[:, 1].astype(float)
        mask = (values >= section_left) & (values <= section_right)
        filtered_data = array[mask]
        mean_value = np.mean(values[~mask])
        aggregated_row = np.array([['X', mean_value]], dtype=object)
        return np.vstack((filtered_data, aggregated_row))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            values = np.array([50, 35, 8, 5, 1, 1])
            data = np.column_stack((labels, values))
            section_left = 4
            section_right = 38
        if test_case_id == 2:
            labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
            values = np.array([50, 35, 8, 5, 1, 1])
            data = np.column_stack((labels, values))
            section_left = 6
            section_right = 38
        return data, section_left, section_right

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data, section_left, section_right = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'lab':['A', 'B', 'C', 'D', 'E', 'F'], 'value':[50, 35, 8, 5, 1, 1]})
df = df.set_index('lab')
section_left = 4
section_right = 38

result = ... # put solution in this variable

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)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, section_left, section_right = data
        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")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            section_left = 4
            section_right = 38
        if test_case_id == 2:
            df = pd.DataFrame(
                {"lab": ["A", "B", "C", "D", "E", "F"], "value": [50, 35, 8, 5, 1, 1]}
            )
            df = df.set_index("lab")
            section_left = 6
            section_right = 38
        return df, section_left, section_right

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, section_left, section_right = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([[1, 4], [2, 5], [3, 6]])

result = ... # put solution in this variable

import numpy as np
import math

def g(arr):
    exp_arr = np.exp(arr)
    return np.hstack((arr, exp_arr))

result = g(arr.copy())

import numpy as np
import math
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        exp_arr = np.exp(arr)
        return np.hstack((arr, exp_arr))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([[1, 4], [2, 5], [3, 6]])
        if test_case_id == 2:
            arr = np.array([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens

import pandas as pd

df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

result = ... # put solution in this variable

import math
def g(df):
    return df.join(df.apply(lambda x: math.e**x).add_prefix('exp_'))

result = g(df.copy())

import pandas as pd
import numpy as np
import math
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.join(df.apply(lambda x: math.e**x).add_prefix("exp_"))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
        if test_case_id == 2:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


import numpy as np

arr = np.array([[1, 0, 3], [4, 5, 6]])

result = ... # put solution in this variable

def g(arr):
    inv_arr = np.where(arr != 0, 1/arr, 0)
    return np.hstack((arr, inv_arr))

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        inv_arr = np.where(arr != 0, 1/arr, 0)
        return np.hstack((arr, inv_arr))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([[1, 2, 3], [4, 5, 6]])
        if test_case_id == 2:
            arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    assert "while" not in solution and "for" not in solution

import pandas as pd

df = pd.DataFrame({"A": [1, 0, 3], "B": [4, 5, 6]})

result = ... # put solution in this variable

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())

import pandas as pd
import numpy as np
import math
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.join(df.apply(lambda x: 1 / x).add_prefix("inv_")).replace(
            math.inf, 0
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
        if test_case_id == 2:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


def g(arr):
    sigmoid = 1 / (1 + np.exp(-arr))
    return np.hstack((arr, sigmoid))

result = g(arr.copy())

import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        sigmoid = 1 / (1 + np.exp(-arr))
        return np.hstack((arr, sigmoid))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([[1, 4], [2, 5], [3, 6]])
        if test_case_id == 2:
            arr = np.array([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens

import math
def g(df):
    return df.join(df.apply(lambda x: 1/(1+math.e**(-x))).add_prefix('sigmoid_'))

result = g(df.copy())

import pandas as pd
import numpy as np
import math
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.join(
            df.apply(lambda x: 1 / (1 + math.e ** (-x))).add_prefix("sigmoid_")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
        if test_case_id == 2:
            df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


def g(a, idx):
    min_indices = np.argmin(a, axis=0)
    masked_a = np.where(np.cumsum(a == a[min_indices, np.arange(a.shape[1])], axis=0), np.nan, a)
    reversed_masked_a = masked_a[::-1]
    max_indices = np.nanargmax(reversed_masked_a, axis=0)
    return idx[::-1][max_indices]

result = g(a, idx)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, idx):
        a = data
        min_indices = np.argmin(a, axis=0)
        masked_a = np.where(np.cumsum(a == a[min_indices, np.arange(a.shape[1])], axis=0), np.nan, a)
        reversed_masked_a = masked_a[::-1]
        max_indices = np.nanargmax(reversed_masked_a, axis=0)
        return idx[::-1][max_indices]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([
                [1.0, 0.9, 1.0],
                [0.9, 0.9, 1.0],
                [0.8, 1.0, 0.5],
                [1.0, 0.3, 0.2],
                [1.0, 0.2, 0.1],
                [0.9, 1.0, 1.0],
                [1.0, 0.9, 1.0],
                [0.6, 0.9, 0.7],
                [1.0, 0.9, 0.8],
                [1.0, 0.8, 0.9],
            ])
            idx = np.arange('2017-01', '2017-01-10', dtype='datetime64[D]')
        if test_case_id == 2:
            a = np.array([
                [1.0, 0.9, 1.0],
                [0.9, 0.9, 1.0],
                [0.8, 1.0, 0.5],
                [1.0, 0.3, 0.2],
                [1.0, 0.2, 0.1],
                [0.9, 1.0, 1.0],
                [0.9, 0.9, 1.0],
                [0.6, 0.9, 0.7],
                [1.0, 0.9, 0.8],
                [1.0, 0.8, 0.9],
            ])
            idx = np.arange('2022-01', '2022-01-10', dtype='datetime64[D]')
        return a, idx

    test_input, idx = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input), idx)
    return test_input, idx, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
a, idx = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, idx, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": (test_input, idx)}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.mask((df == df.min()).cumsum().astype(bool))[::-1].idxmax()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.mask((df == df.min()).cumsum().astype(bool))[::-1].idxmax()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [1.0, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
            idx = pd.date_range("2017", periods=a.shape[0])
            df = pd.DataFrame(a, index=idx, columns=list("abc"))
        if test_case_id == 2:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
            idx = pd.date_range("2022", periods=a.shape[0])
            df = pd.DataFrame(a, index=idx, columns=list("abc"))
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_series_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(a):
    min_indices = np.argmin(a, axis=0)
    mask = np.arange(a.shape[0])[:, None] >= min_indices
    masked_a = np.where(mask, a, -np.inf)
    return np.argmax(masked_a, axis=0)

result = g(a)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        a = data
        min_indices = np.argmin(a, axis=0)
        mask = np.arange(a.shape[0])[:, None] >= min_indices
        masked_a = np.where(mask, a, -np.inf)
        return np.argmax(masked_a, axis=0)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [1.0, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
        if test_case_id == 2:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
        return a

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
a = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.mask(~(df == df.min()).cumsum().astype(bool)).idxmax()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.mask(~(df == df.min()).cumsum().astype(bool)).idxmax()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [1.0, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
            idx = pd.date_range("2017", periods=a.shape[0])
            df = pd.DataFrame(a, index=idx, columns=list("abc"))
        if test_case_id == 2:
            a = np.array(
                [
                    [1.0, 0.9, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.8, 1.0, 0.5],
                    [1.0, 0.3, 0.2],
                    [1.0, 0.2, 0.1],
                    [0.9, 1.0, 1.0],
                    [0.9, 0.9, 1.0],
                    [0.6, 0.9, 0.7],
                    [1.0, 0.9, 0.8],
                    [1.0, 0.8, 0.9],
                ]
            )
            idx = pd.date_range("2022", periods=a.shape[0])
            df = pd.DataFrame(a, index=idx, columns=list("abc"))
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_series_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(data):
    dates = np.array(['2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04', '2016-01-05', '2016-01-06'], dtype='U10')
    users = np.unique(data['user'])
    result = []
    for user in users:
        user_data = data[data['user'] == user]
        user_dates = user_data['dt']
        user_vals = {dt: val for dt, val in zip(user_dates, user_data['val'])}
        for date in dates:
            val = user_vals.get(date, 0)
            result.append((date, user, val))
    return np.array(result, dtype=[('dt', 'U10'), ('user', 'U1'), ('val', 'i4')])

result = g(data)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        dates = np.array(['2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04', '2016-01-05', '2016-01-06'], dtype='U10')
        users = np.unique(data['user'])
        result = []
        for user in users:
            user_data = data[data['user'] == user]
            user_dates = user_data['dt']
            user_vals = {dt: val for dt, val in zip(user_dates, user_data['val'])}
            for date in dates:
                val = user_vals.get(date, 0)
                result.append((date, user, val))
        return np.array(result, dtype=[('dt', 'U10'), ('user', 'U1'), ('val', 'i4')])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ('a', '2016-01-01', 1),
                ('a', '2016-01-02', 33),
                ('b', '2016-01-05', 2),
                ('b', '2016-01-06', 1)
            ], dtype=[('user', 'U1'), ('dt', 'U10'), ('val', 'i4')])
        if test_case_id == 2:
            data = np.array([
                ('c', '2016-02-01', 1),
                ('c', '2016-02-02', 33),
                ('d', '2016-02-05', 2),
                ('d', '2016-02-06', 1)
            ], dtype=[('user', 'U1'), ('dt', 'U10'), ('val', 'i4')])
        return data

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        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()
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": ["a", "a", "b", "b"],
                    "dt": ["2016-01-01", "2016-01-02", "2016-01-05", "2016-01-06"],
                    "val": [1, 33, 2, 1],
                }
            )
            df["dt"] = pd.to_datetime(df["dt"])
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": ["c", "c", "d", "d"],
                    "dt": ["2016-02-01", "2016-02-02", "2016-02-05", "2016-02-06"],
                    "val": [1, 33, 2, 1],
                }
            )
            df["dt"] = pd.to_datetime(df["dt"])
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
from datetime import datetime, timedelta

data = np.array([('a', '2016-01-01', 1), ('a', '2016-01-02', 33), ('b', '2016-01-05', 2), ('b', '2016-01-06', 1)], dtype=[('user', 'U1'), ('dt', 'U10'), ('val', 'i4')])
data['dt'] = np.array([datetime.strptime(date, '%Y-%m-%d') for date in data['dt']])

result = ... # put solution in this variable

def g(data):
    dates = np.array([datetime.strptime(date, '%Y-%m-%d') for date in data['dt']])
    min_date, max_date = dates.min(), dates.max()
    all_dates = np.arange(min_date, max_date + timedelta(days=1), dtype='datetime64[D]')
    users = np.unique(data['user'])
    result = []
    for user in users:
        user_data = data[data['user'] == user]
        max_val = user_data['val'].max()
        for date in all_dates:
            if date in user_data['dt']:
                val = user_data[user_data['dt'] == date]['val'][0]
            else:
                val = max_val
            result.append((date, user, val))
    return np.array(result, dtype=[('dt', 'datetime64[D]'), ('user', 'U1'), ('val', 'i4')])

result = g(data.copy())

import numpy as np
from datetime import datetime, timedelta
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        dates = np.array([datetime.strptime(date, '%Y-%m-%d') for date in data['dt']])
        min_date, max_date = dates.min(), dates.max()
        all_dates = np.arange(min_date, max_date + timedelta(days=1), dtype='datetime64[D]')
        users = np.unique(data['user'])
        result = []
        for user in users:
            user_data = data[data['user'] == user]
            max_val = user_data['val'].max()
            for date in all_dates:
                if date in user_data['dt']:
                    val = user_data[user_data['dt'] == date]['val'][0]
                else:
                    val = max_val
                result.append((date, user, val))
        return np.array(result, dtype=[('dt', 'datetime64[D]'), ('user', 'U1'), ('val', 'i4')])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ('a', '2016-01-01', 1),
                ('a', '2016-01-02', 33),
                ('b', '2016-01-05', 2),
                ('b', '2016-01-06', 1)
            ], dtype=[('user', 'U1'), ('dt', 'U10'), ('val', 'i4')])
            data['dt'] = np.array([datetime.strptime(date, '%Y-%m-%d') for date in data['dt']])
        if test_case_id == 2:
            data = np.array([
                ('c', '2016-02-01', 1),
                ('c', '2016-02-02', 33),
                ('d', '2016-02-05', 2),
                ('d', '2016-02-06', 1)
            ], dtype=[('user', 'U1'), ('dt', 'U10'), ('val', 'i4')])
            data['dt'] = np.array([datetime.strptime(date, '%Y-%m-%d') for date in data['dt']])
        return data

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
from datetime import datetime, timedelta
data = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        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()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": ["a", "a", "b", "b"],
                    "dt": ["2016-01-01", "2016-01-02", "2016-01-05", "2016-01-06"],
                    "val": [1, 33, 2, 1],
                }
            )
            df["dt"] = pd.to_datetime(df["dt"])
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": ["c", "c", "d", "d"],
                    "dt": ["2016-02-01", "2016-02-02", "2016-02-05", "2016-02-06"],
                    "val": [1, 33, 2, 1],
                }
            )
            df["dt"] = pd.to_datetime(df["dt"])
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([
    ['Aaron', 3, 5, 7],
    ['Aaron', 3, 6, 9],
    ['Aaron', 3, 6, 10],
    ['Brave', 4, 6, 0],
    ['Brave', 3, 6, 1],
    ['David', 5, 1, 4]
])

result = ... # put solution in this variable

def g(arr):
    F = {}
    cnt = 0
    for i in range(len(arr)):
        if arr[i, 0] not in F:
            cnt += 1
            F[arr[i, 0]] = cnt
        arr[i, 0] = F[arr[i, 0]]
    return arr

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        F = {}
        cnt = 0
        for i in range(len(arr)):
            if arr[i, 0] not in F:
                cnt += 1
                F[arr[i, 0]] = cnt
            arr[i, 0] = F[arr[i, 0]]
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['Aaron', 3, 5, 7],
                ['Aaron', 3, 6, 9],
                ['Aaron', 3, 6, 10],
                ['Brave', 4, 6, 0],
                ['Brave', 3, 6, 1],
                ['David', 5, 1, 4]
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'name': ['Aaron', 'Aaron', 'Aaron', 'Brave', 'Brave', 'David'],
                   'a': [3, 3, 3, 4, 3, 5],
                   'b': [5, 6, 6, 6, 6, 1],
                   'c': [7, 9, 10, 0, 1, 4]})

result = ... # put solution in this variable

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        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

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "name": ["Aaron", "Aaron", "Aaron", "Brave", "Brave", "David"],
                    "a": [3, 3, 3, 4, 3, 5],
                    "b": [5, 6, 6, 6, 6, 1],
                    "c": [7, 9, 10, 0, 1, 4],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    F = {}
    cnt = 0
    for i in range(len(arr)):
        if arr[i, 1] not in F:
            cnt += 1
            F[arr[i, 1]] = cnt
        arr[i, 1] = F[arr[i, 1]]
    return arr

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        F = {}
        cnt = 0
        for i in range(len(arr)):
            if arr[i, 1] not in F:
                cnt += 1
                F[arr[i, 1]] = cnt
            arr[i, 1] = F[arr[i, 1]]
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['Aaron', 3, 5, 7],
                ['Aaron', 3, 6, 9],
                ['Aaron', 3, 6, 10],
                ['Brave', 4, 6, 0],
                ['Brave', 3, 6, 1],
                ['David', 5, 1, 4]
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        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

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "name": ["Aaron", "Aaron", "Aaron", "Brave", "Brave", "David"],
                    "a": [3, 3, 3, 4, 3, 5],
                    "b": [5, 6, 6, 6, 6, 1],
                    "c": [7, 9, 10, 0, 1, 4],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

example_array = np.array([
    ['Aaron', 3, 5, 7],
    ['Aaron', 3, 6, 9],
    ['Aaron', 3, 6, 10],
    ['Brave', 4, 6, 0],
    ['Brave', 3, 6, 1],
    ['David', 5, 1, 4]
])

def f(arr=example_array):
    # return the solution in this function
    # result = f(arr)
    ###

    F = {}
    cnt = 0
    for i in range(len(arr)):
        if arr[i, 0] not in F:
            cnt += 1
            F[arr[i, 0]] = cnt
        arr[i, 0] = F[arr[i, 0]]
    result = arr

    return result

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        F = {}
        cnt = 0
        for i in range(len(arr)):
            if arr[i, 0] not in F:
                cnt += 1
                F[arr[i, 0]] = cnt
            arr[i, 0] = F[arr[i, 0]]
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['Aaron', 3, 5, 7],
                ['Aaron', 3, 6, 9],
                ['Aaron', 3, 6, 10],
                ['Brave', 4, 6, 0],
                ['Brave', 3, 6, 1],
                ['David', 5, 1, 4]
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
def f(arr):
[insert]
arr = test_input
result = f(arr)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

name  a  b   c
0  Aaron  3  5   7
1  Aaron  3  6   9
2  Aaron  3  6  10
3  Brave  4  6   0
4  Brave  3  6   1

import pandas as pd

example_df = pd.DataFrame({'name': ['Aaron', 'Aaron', 'Aaron', 'Brave', 'Brave', 'David'],
                   'a': [3, 3, 3, 4, 3, 5],
                   'b': [5, 6, 6, 6, 6, 1],
                   'c': [7, 9, 10, 0, 1, 4]})
def f(df=example_df):
    # return the solution in this function
    # result = f(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']]
    result = df

    return result

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        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

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "name": ["Aaron", "Aaron", "Aaron", "Brave", "Brave", "David"],
                    "a": [3, 3, 3, 4, 3, 5],
                    "b": [5, 6, 6, 6, 6, 1],
                    "c": [7, 9, 10, 0, 1, 4],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
def f(df):
[insert]
df = test_input
result = f(df)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

users = np.array(['u1', 'u2', 'u3'])
dates = np.array(['01/12/15', '02/12/15'])
values = np.array([[100, 300], [200, -100], [-50, 200]])
some_bool = np.array([True, False, True])

# put solution in this variable

def g(users, dates, values, some_bool):
    user_col = np.repeat(users, len(dates))
    date_col = np.tile(dates, len(users))
    value_col = values.flatten()
    bool_col = np.repeat(some_bool, len(dates))
    return np.column_stack((user_col, date_col, value_col, bool_col))

df = g(users, dates, values, some_bool)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(users, dates, values, some_bool):
        user_col = np.repeat(users, len(dates))
        date_col = np.tile(dates, len(users))
        value_col = values.flatten()
        bool_col = np.repeat(some_bool, len(dates))
        return np.column_stack((user_col, date_col, value_col, bool_col))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            users = np.array(['u1', 'u2', 'u3'])
            dates = np.array(['01/12/15', '02/12/15'])
            values = np.array([[100, 300], [200, -100], [-50, 200]])
            some_bool = np.array([True, False, True])
        if test_case_id == 2:
            users = np.array(['u1', 'u2', 'u3'])
            dates = np.array(['01/10/22', '02/10/22'])
            values = np.array([[100, 300], [200, -100], [-50, 200]])
            some_bool = np.array([True, False, True])
        return users, dates, values, some_bool

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(*copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
users, dates, values, some_bool = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

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())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df = (
            df.set_index(["user", "someBool"])
            .stack()
            .reset_index(name="value")
            .rename(columns={"level_2": "date"})
        )
        return df[["user", "date", "value", "someBool"]]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": ["u1", "u2", "u3"],
                    "01/12/15": [100, 200, -50],
                    "02/12/15": [300, -100, 200],
                    "someBool": [True, False, True],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": ["u1", "u2", "u3"],
                    "01/10/22": [100, 200, -50],
                    "02/10/22": [300, -100, 200],
                    "someBool": [True, False, True],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

user = np.array(['u1', 'u2', 'u3'])
date_01_12_15 = np.array([100, 200, -50])
date_02_12_15 = np.array([300, -100, 200])
some_bool = np.array([True, False, True])

# Combine into a structured array
df = np.core.records.fromarrays([user, date_01_12_15, date_02_12_15, some_bool], names='user, 01/12/15, 02/12/15, someBool')

# df = ... # put solution in this variable

def g(df):
    user = df['user']
    date_01_12_15 = df['01/12/15']
    others = np.concatenate([np.full(len(user), '02/12/15'), np.full(len(user), 'someBool')])
    value = np.concatenate([df['02/12/15'], df['someBool']])
    user_repeated = np.repeat(user, 2)
    date_repeated = np.repeat(date_01_12_15, 2)
    return np.core.records.fromarrays([user_repeated, date_repeated, others, value], names='user, 01/12/15, others, value')

df = g(df)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        user = data['user']
        date_01_12_15 = data['01/12/15']
        others = np.concatenate([np.full(len(user), '02/12/15'), np.full(len(user), 'someBool')])
        value = np.concatenate([data['02/12/15'], data['someBool']])
        user_repeated = np.repeat(user, 2)
        date_repeated = np.repeat(date_01_12_15, 2)
        return np.core.records.fromarrays([user_repeated, date_repeated, others, value], names='user, 01/12/15, others, value')

    def define_test_input(test_case_id):
        if test_case_id == 1:
            user = np.array(['u1', 'u2', 'u3'])
            date_01_12_15 = np.array([100, 200, -50])
            date_02_12_15 = np.array([300, -100, 200])
            some_bool = np.array([True, False, True])
        if test_case_id == 2:
            user = np.array(['u1', 'u2', 'u3'])
            date_01_12_15 = np.array([300, -100, 200])
            date_02_12_15 = np.array([100, 200, -50])
            some_bool = np.array([True, False, True])
        return np.core.records.fromarrays([user, date_01_12_15, date_02_12_15, some_bool], names='user, 01/12/15, 02/12/15, someBool')

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.set_index(['user','01/12/15']).stack().reset_index(name='value').rename(columns={'level_2':'others'})

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return (
            df.set_index(["user", "01/12/15"])
            .stack()
            .reset_index(name="value")
            .rename(columns={"level_2": "others"})
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": ["u1", "u2", "u3"],
                    "01/12/15": [100, 200, -50],
                    "02/12/15": [300, -100, 200],
                    "someBool": [True, False, True],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": ["u1", "u2", "u3"],
                    "01/12/15": [300, -100, 200],
                    "02/12/15": [100, 200, -50],
                    "someBool": [True, False, True],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.random.rand(4,5)
columns = [1, 4]

result = ... # put solution in this variable

def g(arr, columns):
    return arr[arr[:, 2] > 0.5][:, columns]

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr, columns = data
        return arr[arr[:, 2] > 0.5][:, columns]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(2)
            arr = np.random.rand(4, 5)
            columns = [1, 4]
        return arr, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr, columns = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

df = DataFrame(np.random.rand(4,5), columns = list('abcde'))

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(4,5), columns = list('abcde'))
columns = ['b','e']

result = ... # put solution in this variable

def g(df, columns):
    return df.loc[df['c']>0.5,columns]

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, columns = data
        return df.loc[df["c"] > 0.5, columns]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(2)
            df = pd.DataFrame(np.random.rand(4, 5), columns=list("abcde"))
            columns = ["b", "e"]
        return df, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, columns = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.random.rand(4,5)
columns = [0, 1, 4]

result = ... # put solution in this variable

mask = arr[:, 2] > 0.45
result = arr[mask][:, columns]

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr, columns = data
        mask = arr[:, 2] > 0.45
        return arr[mask][:, columns]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(2)
            arr = np.random.rand(4, 5)
            columns = [0, 1, 4]
        if test_case_id == 2:
            np.random.seed(42)
            arr = np.random.rand(4, 5)
            columns = [0, 1, 4]
        return arr, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr, columns = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(4,5), columns = list('abcde'))
columns = ['a','b','e']

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, columns = data
        return df.loc[df["c"] > 0.45, columns]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(2)
            df = pd.DataFrame(np.random.rand(4, 5), columns=list("abcde"))
            columns = ["a", "b", "e"]
        if test_case_id == 2:
            np.random.seed(42)
            df = pd.DataFrame(np.random.rand(4, 5), columns=list("abcde"))
            columns = ["a", "b", "e"]
        return df, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, columns = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
def f(arr, columns=[1, 4]):
    # return the solution in this function
    # result = f(arr, columns)
    ###

    ans = arr[arr[:, 2] > 0.5][:, columns]
    sums = ans.sum(axis=1, keepdims=True)
    result = np.hstack((ans, sums))

    return result

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr, columns = data
        ans = arr[arr[:, 2] > 0.5][:, columns]
        sums = ans.sum(axis=1, keepdims=True)
        return np.hstack((ans, sums))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            arr = np.random.rand(4, 5)
            columns = [1, 4]
        return arr, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
def f(arr, columns):
[insert]
arr, columns = test_input
result = f(arr, columns)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
def f(df, columns=['b', 'e']):
    # return the solution in this function
    # result = f(df, columns)
    ###

    ans = df[df.c > 0.5][columns]
    ans['sum'] = ans.sum(axis=1)
    result = ans

    return result

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, columns = data
        ans = df[df.c > 0.5][columns]
        ans["sum"] = ans.sum(axis=1)
        return ans

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            df = pd.DataFrame(np.random.rand(4, 5), columns=list("abcde"))
            columns = ["b", "e"]
        return df, columns

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
def f(df, columns):
[insert]
df, columns = test_input
result = f(df, columns)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([1, 1, 4, 5, 1, 4])

result = ... # put solution in this variable

def g(arr):
    return np.add.reduceat(arr, np.arange(0, len(arr), 4))

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return np.add.reduceat(arr, np.arange(0, len(arr), 4))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([1, 1, 4, 5, 1, 4])
        if test_case_id == 2:
            arr = np.array([1, 9, 2, 6, 0, 8])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'col1':[1, 1, 4, 5, 1, 4]})

result = ... # put solution in this variable

def g(df):
    return df.groupby(df.index // 4).sum()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.groupby(df.index // 4).sum()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"col1": [1, 1, 4, 5, 1, 4]})
        if test_case_id == 2:
            df = pd.DataFrame({"col1": [1, 9, 2, 6, 0, 8]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([2, 1, 3, 1, 0])

result = ... # put solution in this variable

def g(arr):
    n = len(arr)
    indices = (np.arange(n) + (-n % 3)) // 3
    unique_indices = np.unique(indices)
    return np.array([arr[indices == i].mean() for i in unique_indices])

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        n = len(arr)
        indices = (np.arange(n) + (-n % 3)) // 3
        unique_indices = np.unique(indices)
        return np.array([arr[indices == i].mean() for i in unique_indices])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([2, 1, 3, 1, 0])
        if test_case_id == 2:
            arr = np.array([1, 9, 2, 6, 8])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_almost_equal(result, ans, decimal=3)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'col1':[2, 1, 3, 1, 0]})

result = ... # put solution in this variable

def g(df):
    return df.groupby((df.index+(-df.size % 3)) // 3).mean()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.groupby((df.index + (-df.size % 3)) // 3).mean()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"col1": [2, 1, 3, 1, 0]})
        if test_case_id == 2:
            df = pd.DataFrame({"col1": [1, 9, 2, 6, 8]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)