def g(data):
    unique_groups = np.unique(data[['Sp', 'Value']])
    result = []
    for group in unique_groups:
        mask = (data['Sp'] == group['Sp']) & (data['Value'] == group['Value'])
        group_data = data[mask]
        max_count = np.max(group_data['count'])
        result.extend(group_data[group_data['count'] == max_count])
    return np.array(result, dtype=data.dtype)

result = g(data.copy())

import numpy as np
import copy

dtype = [('Sp', 'U3'), ('Value', 'U2'), ('Mt', 'U3'), ('count', 'i4')]

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_groups = np.unique(data[['Sp', 'Value']])
        result = []
        for group in unique_groups:
            mask = (data['Sp'] == group['Sp']) & (data['Value'] == group['Value'])
            group_data = data[mask]
            max_count = np.max(group_data['count'])
            result.extend(group_data[group_data['count'] == max_count])
        return np.array(result, dtype=data.dtype)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ('MM1', 'S1', 'a', 3),
                ('MM1', 'S1', 'n', 2),
                ('MM1', 'S3', 'cb', 5),
                ('MM2', 'S3', 'mk', 8),
                ('MM2', 'S4', 'bg', 10),
                ('MM2', 'S4', 'dgd', 1),
                ('MM4', 'S2', 'rd', 2),
                ('MM4', 'S2', 'cb', 2),
                ('MM4', 'S2', 'uyi', 7)
            ], dtype=dtype)
        if test_case_id == 2:
            data = np.array([
                ('MM2', 'S4', 'bg', 10),
                ('MM2', 'S4', 'dgd', 1),
                ('MM4', 'S2', 'rd', 2),
                ('MM4', 'S2', 'cb', 8),
                ('MM4', 'S2', 'uyi', 8)
            ], 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(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)

    Sp Value   Mt  count
0  MM1    S1    a      3
1  MM1    S1    n      2
2  MM1    S3   cb      5
3  MM2    S3   mk      8
4  MM2    S4   bg     10
5  MM2    S4  dgd      1
6  MM4    S2   rd      2
7  MM4    S2   cb      2
8  MM4    S2  uyi      7

def g(df):
    return df[df.groupby(['Sp', 'Value'])['count'].transform(max) == df['count']]

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[df.groupby(["Sp", "Value"])["count"].transform(max) == df["count"]]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Sp": [
                        "MM1",
                        "MM1",
                        "MM1",
                        "MM2",
                        "MM2",
                        "MM2",
                        "MM4",
                        "MM4",
                        "MM4",
                    ],
                    "Value": ["S1", "S1", "S3", "S3", "S4", "S4", "S2", "S2", "S2"],
                    "Mt": ["a", "n", "cb", "mk", "bg", "dgd", "rd", "cb", "uyi"],
                    "count": [3, 2, 5, 8, 10, 1, 2, 2, 7],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Sp": ["MM2", "MM2", "MM4", "MM4", "MM4"],
                    "Mt": ["S4", "S4", "S2", "S2", "S2"],
                    "Value": ["bg", "dgd", "rd", "cb", "uyi"],
                    "count": [10, 1, 2, 8, 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)


categories = np.array(['Foo', 'Bar', 'Cho', 'Foo'])
filter_list = ['Foo', 'Bar']

import numpy as np

categories = np.array(['Foo', 'Bar', 'Cho', 'Foo'])
indices = np.array([1, 2, 3, 4])
filter_list = ['Foo', 'Bar']

result = ... # put solution in this variable

def g(categories, filter_list):
    mask = np.isin(categories, filter_list)
    return indices[mask], categories[mask]

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        categories, indices, filter_list = data
        mask = np.isin(categories, filter_list)
        return indices[mask], categories[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            categories = np.array(['Foo', 'Bar', 'Cho', 'Foo'])
            indices = np.array([1, 2, 3, 4])
            filter_list = ['Foo', 'Bar']
        if test_case_id == 2:
            categories = np.array(['Foo', 'Bar', 'Cho', 'Foo', 'Bar'])
            indices = np.array([1, 2, 3, 4, 5])
            filter_list = ['Foo', 'Bar']
        return categories, indices, filter_list

    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
categories, indices, filter_list = 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({'Index': [1, 2, 3, 4], 'Category': ['Foo', 'Bar', 'Cho', 'Foo']})

import pandas as pd

df=pd.DataFrame({"Category":['Foo','Bar','Cho','Foo'],'Index':[1,2,3,4]})
filter_list=['Foo','Bar']

result = ... # put solution in this variable

def g(df, filter_list):
    return df.query("Category == @filter_list")

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, filter_list = data
        return df.query("Category == @filter_list")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"Category": ["Foo", "Bar", "Cho", "Foo"], "Index": [1, 2, 3, 4]}
            )
            filter_list = ["Foo", "Bar"]
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Category": ["Foo", "Bar", "Cho", "Foo", "Bar"],
                    "Index": [1, 2, 3, 4, 5],
                }
            )
            filter_list = ["Foo", "Bar"]
        return df, filter_list

    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, filter_list = 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)


Index Category
1     Foo
2     Bar
3     Cho
4     Foo

def g(categories, indices, filter_list):
    mask = np.isin(categories, filter_list, invert=True)
    filtered_indices = indices[mask]
    filtered_categories = categories[mask]
    return filtered_indices, filtered_categories

result = g(categories.copy(), indices.copy(), filter_list)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        categories, indices, filter_list = data
        mask = np.isin(categories, filter_list, invert=True)
        filtered_indices = indices[mask]
        filtered_categories = categories[mask]
        return filtered_indices, filtered_categories

    def define_test_input(test_case_id):
        if test_case_id == 1:
            categories = np.array(['Foo', 'Bar', 'Cho', 'Foo'])
            indices = np.array([1, 2, 3, 4])
            filter_list = ['Foo', 'Bar']
        if test_case_id == 2:
            categories = np.array(['Foo', 'Bar', 'Cho', 'Foo', 'Bar'])
            indices = np.array([1, 2, 3, 4, 5])
            filter_list = ['Foo', 'Bar']
        return categories, indices, filter_list

    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
categories, indices, filter_list = 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, filter_list):
    return df.query("Category != @filter_list")

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, filter_list = data
        return df.query("Category != @filter_list")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"Category": ["Foo", "Bar", "Cho", "Foo"], "Index": [1, 2, 3, 4]}
            )
            filter_list = ["Foo", "Bar"]
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Category": ["Foo", "Bar", "Cho", "Foo", "Bar"],
                    "Index": [1, 2, 3, 4, 5],
                }
            )
            filter_list = ["Foo", "Bar"]
        return df, filter_list

    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, filter_list = 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):
    num_rows = data.shape[0]
    num_cols = len(data.dtype.names)
    result = []
    for col_idx, col_name in enumerate(data.dtype.names):
        for row_idx in range(num_rows):
            row = [chr(69 + col_idx), chr(66 + col_idx // 2), 'A', data[row_idx][col_name]]
            result.append(row)
    return np.array(result, dtype='O')

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        num_rows = data.shape[0]
        num_cols = len(data.dtype.names)
        result = []
        for col_idx, col_name in enumerate(data.dtype.names):
            for row_idx in range(num_rows):
                row = [chr(69 + col_idx), chr(66 + col_idx // 2), 'A', data[row_idx][col_name]]
                result.append(row)
        return np.array(result, dtype='O')

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ('a', 1, 2, 3, 7, 2),
                ('b', 3, 4, 6, 2, 9),
                ('c', 5, 6, 2, 3, 5)
            ], dtype=[('col1', 'U1'), ('col2', 'i4'), ('col3', 'i4'), ('col4', 'i4'), ('col5', 'i4'), ('col6', 'i4')])
        if test_case_id == 2:
            data = np.array([
                ('a', 1, 2, 3, 7, 2),
                ('b', 3, 4, 6, 2, 9),
                ('c', 5, 6, 2, 3, 5)
            ], dtype=[('col1', 'U1'), ('col2', 'i4'), ('col3', 'i4'), ('col4', 'i4'), ('col5', 'i4'), ('col6', '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:
        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)

def g(df):
    result = pd.melt(df, value_vars=df.columns.tolist())
    cols = result.columns[:-1]
    for idx in result.index:
        t = result.loc[idx, cols]
        for i in range(len(cols)):
            result.loc[idx, cols[i]] = t[cols[-i-1]]
    return result

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        result = pd.melt(df, value_vars=df.columns.tolist())
        cols = result.columns[:-1]
        for idx in result.index:
            t = result.loc[idx, cols]
            for i in range(len(cols)):
                result.loc[idx, cols[i]] = t[cols[-i - 1]]
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "col1": {0: "a", 1: "b", 2: "c"},
                    "col2": {0: 1, 1: 3, 2: 5},
                    "col3": {0: 2, 1: 4, 2: 6},
                    "col4": {0: 3, 1: 6, 2: 2},
                    "col5": {0: 7, 1: 2, 2: 3},
                    "col6": {0: 2, 1: 9, 2: 5},
                }
            )
            df.columns = [list("AAAAAA"), list("BBCCDD"), list("EFGHIJ")]
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "col1": {0: "a", 1: "b", 2: "c"},
                    "col2": {0: 1, 1: 3, 2: 5},
                    "col3": {0: 2, 1: 4, 2: 6},
                    "col4": {0: 3, 1: 6, 2: 2},
                    "col5": {0: 7, 1: 2, 2: 3},
                    "col6": {0: 2, 1: 9, 2: 5},
                }
            )
            df.columns = [
                list("AAAAAA"),
                list("BBBCCC"),
                list("DDEEFF"),
                list("GHIJKL"),
            ]
        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 running_cumsum(id_arr, val_arr):
    unique_ids = np.unique(id_arr)
    cumsum_arr = np.zeros_like(val_arr)
    for uid in unique_ids:
        mask = id_arr == uid
        cumsum_arr[mask] = np.cumsum(val_arr[mask])
    return cumsum_arr

cumsum_arr = running_cumsum(id_arr, val_arr)
result = np.column_stack((id_arr, stuff_arr, val_arr, cumsum_arr))

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(id_arr, val_arr):
        unique_ids = np.unique(id_arr)
        cumsum_arr = np.zeros_like(val_arr)
        for uid in unique_ids:
            mask = id_arr == uid
            cumsum_arr[mask] = np.cumsum(val_arr[mask])
        return cumsum_arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            id_arr = np.array(['A', 'B', 'A', 'C', 'D', 'B', 'C'])
            val_arr = np.array([1, 2, -3, 1, 5, 6, -2])
            stuff_arr = np.array(['12', '23232', '13', '1234', '3235', '3236', '732323'])
        elif test_case_id == 2:
            np.random.seed(19260817)
            id_arr = np.array(['A', 'B'] * 10 + ['C'] * 10)
            val_arr = np.random.randint(0, 100, 30)
            stuff_arr = np.array([''] * 30)  # Placeholder
        elif test_case_id == 3:
            np.random.seed(19260817)
            id_arr = np.random.choice(list('ABCDE'), 1000)
            val_arr = np.random.randint(-1000, 1000, 1000)
            stuff_arr = np.array([''] * 1000)  # Placeholder
        return id_arr, val_arr, stuff_arr

    id_arr, val_arr, stuff_arr = define_test_input(test_case_id)
    expected_cumsum = generate_ans(copy.deepcopy(id_arr), copy.deepcopy(val_arr))
    return id_arr, val_arr, stuff_arr, expected_cumsum

def exec_test(result, expected_result):
    try:
        assert np.array_equal(result[:, 3].astype(int), expected_result)
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
id_arr, val_arr, stuff_arr = test_input
[insert]
result = np.column_stack((id_arr, stuff_arr, val_arr, cumsum_arr))
'''

def test_execution(solution: str):
    code = exec_context.replace('[insert]', solution)
    for i in range(3):
        id_arr, val_arr, stuff_arr, expected_cumsum = generate_test_case(i + 1)
        test_input = (id_arr, val_arr, stuff_arr)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        assert exec_test(test_env['result'], expected_cumsum)

def g(df):
    df['cumsum'] = df.groupby('id')['val'].transform(pd.Series.cumsum)
    return df

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["cumsum"] = df.groupby("id")["val"].transform(pd.Series.cumsum)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame.from_dict(
                {
                    "id": ["A", "B", "A", "C", "D", "B", "C"],
                    "val": [1, 2, -3, 1, 5, 6, -2],
                    "stuff": ["12", "23232", "13", "1234", "3235", "3236", "732323"],
                }
            )
        elif test_case_id == 2:
            np.random.seed(19260817)
            df = pd.DataFrame(
                {
                    "id": ["A", "B"] * 10 + ["C"] * 10,
                    "val": np.random.randint(0, 100, 30),
                }
            )
        elif test_case_id == 3:
            np.random.seed(19260817)
            df = pd.DataFrame(
                {
                    "id": np.random.choice(list("ABCDE"), 1000),
                    "val": np.random.randint(-1000, 1000, 1000),
                }
            )
        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(3):
        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 running_sum(arr):
    ids, vals = arr[:, 0], arr[:, 1].astype(int)
    unique_ids = np.unique(ids)
    cumsum = np.zeros_like(vals)
    for uid in unique_ids:
        mask = ids == uid
        cumsum[mask] = np.cumsum(vals[mask])
    return np.column_stack((arr, cumsum))

arr = running_sum(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        ids, vals = data[:, 0], data[:, 1].astype(int)
        unique_ids = np.unique(ids)
        cumsum = np.zeros_like(vals)
        for uid in unique_ids:
            mask = ids == uid
            cumsum[mask] = np.cumsum(vals[mask])
        return np.column_stack((data, cumsum))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['A', 1, '12'],
                ['B', 2, '23232'],
                ['A', -3, '13'],
                ['C', 1, '1234'],
                ['D', 5, '3235'],
                ['B', 6, '3236'],
                ['C', -2, '732323'],
            ], dtype=object)
        elif test_case_id == 2:
            np.random.seed(19260817)
            ids = np.array(['A', 'B'] * 10 + ['C'] * 10)
            vals = np.random.randint(0, 100, 30)
            arr = np.column_stack((ids, vals))
        elif test_case_id == 3:
            np.random.seed(19260817)
            ids = np.random.choice(list('ABCDE'), 1000)
            vals = np.random.randint(-1000, 1000, 1000)
            arr = np.column_stack((ids, vals))
        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]
result=arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        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

l = np.array(['left', 'right', 'left', 'right', 'left', 'right'])
r = np.array(['right', 'left', 'right', 'left', 'right', 'left'])
v = np.array([-1, 1, -1, 1, -1, np.nan])

result = ... # put solution in this variable

def g(l, v):
    unique_labels = np.unique(l)
    result = {}
    for label in unique_labels:
        values = v[l == label]
        if np.isnan(values).any():
            result[label] = np.nan
        else:
            result[label] = np.sum(values)
    return result

result = g(l, v)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(l, v):
        unique_labels = np.unique(l)
        result = {}
        for label in unique_labels:
            values = v[l == label]
            if np.isnan(values).any():
                result[label] = np.nan
            else:
                result[label] = np.sum(values)
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            l = np.array(['left', 'right', 'left', 'right', 'left', 'right'])
            r = np.array(['right', 'left', 'right', 'left', 'right', 'left'])
            v = np.array([-1, 1, -1, 1, -1, np.nan])
        if test_case_id == 2:
            l = np.array(['left', 'right', 'left', 'left', 'right', 'right'])
            r = np.array(['right', 'left', 'right', 'right', 'left', 'left'])
            v = np.array([-1, 1, -1, -1, 1, np.nan])
        return l, v

    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
l, v = 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

d = {'l':  ['left', 'right', 'left', 'right', 'left', 'right'],
     'r': ['right', 'left', 'right', 'left', 'right', 'left'],
     'v': [-1, 1, -1, 1, -1, np.nan]}
df = pd.DataFrame(d)

result = ... # put solution in this variable

def g(df):
    return df.groupby('l')['v'].apply(pd.Series.sum,skipna=False)

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("l")["v"].apply(pd.Series.sum, skipna=False)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            d = {
                "l": ["left", "right", "left", "right", "left", "right"],
                "r": ["right", "left", "right", "left", "right", "left"],
                "v": [-1, 1, -1, 1, -1, np.nan],
            }
            df = pd.DataFrame(d)
        if test_case_id == 2:
            d = {
                "l": ["left", "right", "left", "left", "right", "right"],
                "r": ["right", "left", "right", "right", "left", "left"],
                "v": [-1, 1, -1, -1, 1, np.nan],
            }
            df = pd.DataFrame(d)
        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)


l = np.array(['left', 'right', 'left', 'right', 'left', 'right']); r = np.array(['right', 'left', 'right', 'left', 'right', 'left']); v = np.array([-1, 1, -1, 1, -1, np.nan])

def g(l, r, v):
    unique_r = np.unique(r)
    result = {}
    for val in unique_r:
        mask = r == val
        if np.isnan(v[mask]).any():
            result[val] = np.nan
        else:
            result[val] = np.sum(v[mask])
    return result

result = g(l, r, v)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(l, r, v):
        unique_r = np.unique(r)
        result = {}
        for val in unique_r:
            mask = r == val
            if np.isnan(v[mask]).any():
                result[val] = np.nan
            else:
                result[val] = np.sum(v[mask])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            l = np.array(['left', 'right', 'left', 'right', 'left', 'right'])
            r = np.array(['right', 'left', 'right', 'left', 'right', 'left'])
            v = np.array([-1, 1, -1, 1, -1, np.nan])
        if test_case_id == 2:
            l = np.array(['left', 'right', 'left', 'left', 'right', 'right'])
            r = np.array(['right', 'left', 'right', 'right', 'left', 'left'])
            v = np.array([-1, 1, -1, -1, 1, np.nan])
        return l, r, v

    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
l, r, v = 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)

d = {'l':  ['left', 'right', 'left', 'right', 'left', 'right'], 'r': ['right', 'left', 'right', 'left', 'right', 'left'], 'v': [-1, 1, -1, 1, -1, np.nan]} df = pd.DataFrame(d)

def g(df):
    return df.groupby('r')['v'].apply(pd.Series.sum,skipna=False)

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("r")["v"].apply(pd.Series.sum, skipna=False)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            d = {
                "l": ["left", "right", "left", "right", "left", "right"],
                "r": ["right", "left", "right", "left", "right", "left"],
                "v": [-1, 1, -1, 1, -1, np.nan],
            }
            df = pd.DataFrame(d)
        if test_case_id == 2:
            d = {
                "l": ["left", "right", "left", "left", "right", "right"],
                "r": ["right", "left", "right", "right", "left", "left"],
                "v": [-1, 1, -1, -1, 1, np.nan],
            }
            df = pd.DataFrame(d)
        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)


import numpy as np

Column1 = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
Column2 = np.array([4, 3, 6, 8, 3, 4, 1, 4, 3])
Column3 = np.array([7, 3, 3, 1, 2, 2, 3, 2, 7])
Column4 = np.array([9, 8, 7, 6, 5, 4, 3, 2, 1])
Column5 = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1])

columns = [Column1, Column2, Column3, Column4, Column5]
result = ... # put solution in this variable

def get_relation(col1, col2):
    unique_col1 = np.unique(col1, return_counts=True)[1]
    unique_col2 = np.unique(col2, return_counts=True)[1]
    first_max = unique_col1.max()
    second_max = unique_col2.max()
    if first_max == 1:
        if second_max == 1:
            return 'one-to-one'
        else:
            return 'one-to-many'
    else:
        if second_max == 1:
            return 'many-to-one'
        else:
            return 'many-to-many'

def g(columns):
    n = len(columns)
    result = np.empty((n, n), dtype=object)
    for i in range(n):
        for j in range(n):
            if i == j:
                result[i, j] = 'NaN'
            else:
                result[i, j] = get_relation(columns[i], columns[j])
    return result

result = g(columns)

import numpy as np
import copy

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

        def get_relation(col1, col2):
            unique_col1 = np.unique(col1, return_counts=True)[1]
            unique_col2 = np.unique(col2, return_counts=True)[1]
            first_max = unique_col1.max()
            second_max = unique_col2.max()
            if first_max == 1:
                if second_max == 1:
                    return 'one-to-one'
                else:
                    return 'one-to-many'
            else:
                if second_max == 1:
                    return 'many-to-one'
                else:
                    return 'many-to-many'

        n = len(columns)
        result = np.empty((n, n), dtype=object)
        for i in range(n):
            for j in range(n):
                if i == j:
                    result[i, j] = 'NaN'
                else:
                    result[i, j] = get_relation(columns[i], columns[j])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            columns = [
                np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]),
                np.array([4, 3, 6, 8, 3, 4, 1, 4, 3]),
                np.array([7, 3, 3, 1, 2, 2, 3, 2, 7]),
                np.array([9, 8, 7, 6, 5, 4, 3, 2, 1]),
                np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]),
            ]
        if test_case_id == 2:
            columns = [
                np.array([4, 3, 6, 8, 3, 4, 1, 4, 3]),
                np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]),
                np.array([7, 3, 3, 1, 2, 2, 3, 2, 7]),
                np.array([9, 8, 7, 6, 5, 4, 3, 2, 1]),
                np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]),
            ]
        return 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_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
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)

def get_relation(df, col1, col2):
    first_max = df[[col1, col2]].groupby(col1).count().max()[0]
    second_max = df[[col1, col2]].groupby(col2).count().max()[0]
    if first_max==1:
        if second_max==1:
            return 'one-to-one'
        else:
            return 'one-to-many'
    else:
        if second_max==1:
            return 'many-to-one'
        else:
            return 'many-to-many'

def g(df):
    result = pd.DataFrame(index=df.columns, columns=df.columns)
    for col_i in df.columns:
        for col_j in df.columns:
            if col_i == col_j:
                continue
            result.loc[col_i, col_j] = get_relation(df, col_i, col_j)
    return result

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

        def get_relation(df, col1, col2):
            first_max = df[[col1, col2]].groupby(col1).count().max()[0]
            second_max = df[[col1, col2]].groupby(col2).count().max()[0]
            if first_max == 1:
                if second_max == 1:
                    return "one-to-one"
                else:
                    return "one-to-many"
            else:
                if second_max == 1:
                    return "many-to-one"
                else:
                    return "many-to-many"

        result = pd.DataFrame(index=df.columns, columns=df.columns)
        for col_i in df.columns:
            for col_j in df.columns:
                if col_i == col_j:
                    continue
                result.loc[col_i, col_j] = get_relation(df, col_i, col_j)
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Column1": [1, 2, 3, 4, 5, 6, 7, 8, 9],
                    "Column2": [4, 3, 6, 8, 3, 4, 1, 4, 3],
                    "Column3": [7, 3, 3, 1, 2, 2, 3, 2, 7],
                    "Column4": [9, 8, 7, 6, 5, 4, 3, 2, 1],
                    "Column5": [1, 1, 1, 1, 1, 1, 1, 1, 1],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Column1": [4, 3, 6, 8, 3, 4, 1, 4, 3],
                    "Column2": [1, 1, 1, 1, 1, 1, 1, 1, 1],
                    "Column3": [7, 3, 3, 1, 2, 2, 3, 2, 7],
                    "Column4": [9, 8, 7, 6, 5, 4, 3, 2, 1],
                    "Column5": [1, 2, 3, 4, 5, 6, 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 get_relation(arr1, arr2):
    unique1, counts1 = np.unique(arr1, return_counts=True)
    unique2, counts2 = np.unique(arr2, return_counts=True)
    first_max = max(counts1)
    second_max = max(counts2)
    if first_max == 1:
        if second_max == 1:
            return 'one-2-one'
        else:
            return 'one-2-many'
    else:
        if second_max == 1:
            return 'many-2-one'
        else:
            return 'many-2-many'

def g(columns):
    col_names = list(columns.keys())
    result = np.empty((len(col_names), len(col_names)), dtype=object)
    for i, col_i in enumerate(col_names):
        for j, col_j in enumerate(col_names):
            if i == j:
                result[i, j] = 'NaN'
            else:
                result[i, j] = get_relation(columns[col_i], columns[col_j])
    return result

result = g(columns)

import numpy as np
import copy

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

        def get_relation(arr1, arr2):
            unique1, counts1 = np.unique(arr1, return_counts=True)
            unique2, counts2 = np.unique(arr2, return_counts=True)
            first_max = max(counts1)
            second_max = max(counts2)
            if first_max == 1:
                if second_max == 1:
                    return 'one-2-one'
                else:
                    return 'one-2-many'
            else:
                if second_max == 1:
                    return 'many-2-one'
                else:
                    return 'many-2-many'

        col_names = list(columns.keys())
        result = np.empty((len(col_names), len(col_names)), dtype=object)
        for i, col_i in enumerate(col_names):
            for j, col_j in enumerate(col_names):
                if i == j:
                    result[i, j] = 'NaN'
                else:
                    result[i, j] = get_relation(columns[col_i], columns[col_j])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            columns = {
                'Column1': np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]),
                'Column2': np.array([4, 3, 6, 8, 3, 4, 1, 4, 3]),
                'Column3': np.array([7, 3, 3, 1, 2, 2, 3, 2, 7]),
                'Column4': np.array([9, 8, 7, 6, 5, 4, 3, 2, 1]),
                'Column5': np.array([1, 1, 1, 1, 1, 1, 1, 1, 1])
            }
        if test_case_id == 2:
            columns = {
                'Column1': np.array([4, 3, 6, 8, 3, 4, 1, 4, 3]),
                'Column2': np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]),
                'Column3': np.array([7, 3, 3, 1, 2, 2, 3, 2, 7]),
                'Column4': np.array([9, 8, 7, 6, 5, 4, 3, 2, 1]),
                'Column5': np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
            }
        return 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_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
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)

def get_relation(df, col1, col2):
    first_max = df[[col1, col2]].groupby(col1).count().max()[0]
    second_max = df[[col1, col2]].groupby(col2).count().max()[0]
    if first_max==1:
        if second_max==1:
            return 'one-2-one'
        else:
            return 'one-2-many'
    else:
        if second_max==1:
            return 'many-2-one'
        else:
            return 'many-2-many'

def g(df):
    result = pd.DataFrame(index=df.columns, columns=df.columns)
    for col_i in df.columns:
        for col_j in df.columns:
            if col_i == col_j:
                continue
            result.loc[col_i, col_j] = get_relation(df, col_i, col_j)
    return result

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

        def get_relation(df, col1, col2):
            first_max = df[[col1, col2]].groupby(col1).count().max()[0]
            second_max = df[[col1, col2]].groupby(col2).count().max()[0]
            if first_max == 1:
                if second_max == 1:
                    return "one-2-one"
                else:
                    return "one-2-many"
            else:
                if second_max == 1:
                    return "many-2-one"
                else:
                    return "many-2-many"

        result = pd.DataFrame(index=df.columns, columns=df.columns)
        for col_i in df.columns:
            for col_j in df.columns:
                if col_i == col_j:
                    continue
                result.loc[col_i, col_j] = get_relation(df, col_i, col_j)
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Column1": [1, 2, 3, 4, 5, 6, 7, 8, 9],
                    "Column2": [4, 3, 6, 8, 3, 4, 1, 4, 3],
                    "Column3": [7, 3, 3, 1, 2, 2, 3, 2, 7],
                    "Column4": [9, 8, 7, 6, 5, 4, 3, 2, 1],
                    "Column5": [1, 1, 1, 1, 1, 1, 1, 1, 1],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Column1": [4, 3, 6, 8, 3, 4, 1, 4, 3],
                    "Column2": [1, 1, 1, 1, 1, 1, 1, 1, 1],
                    "Column3": [7, 3, 3, 1, 2, 2, 3, 2, 7],
                    "Column4": [9, 8, 7, 6, 5, 4, 3, 2, 1],
                    "Column5": [1, 2, 3, 4, 5, 6, 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)


import numpy as np

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

result = ... # put solution in this variable

import numpy as np

def g(arr):
    family = np.where((arr[:, 1] + arr[:, 2]) >= 1, 'Has Family', 'No Family')
    unique_groups = np.unique(family)
    means = {}
    for group in unique_groups:
        means[group] = arr[family == group, 0].mean()
    return means

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        family = np.where((arr[:, 1] + arr[:, 2]) >= 1, 'Has Family', 'No Family')
        unique_groups = np.unique(family)
        means = {}
        for group in unique_groups:
            means[group] = arr[family == group, 0].mean()
        return means

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [0, 1, 0],
                [1, 1, 0],
                [1, 0, 0],
                [1, 1, 0],
                [0, 0, 1],
            ])
        if test_case_id == 2:
            arr = np.array([
                [1, 0, 1],
                [0, 0, 1],
                [0, 1, 1],
                [0, 0, 1],
                [1, 1, 0],
            ])
        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)

import pandas as pd

df = pd.DataFrame({'Survived': [0,1,1,1,0],
                   'SibSp': [1,1,0,1,0],
                   'Parch': [0,0,0,0,1]})

result = ... # put solution in this variable

import numpy as np
def g(df):
    family = np.where((df['SibSp'] + df['Parch']) >= 1 , 'Has Family', 'No Family')
    return df.groupby(family)['Survived'].mean()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        family = np.where((df["SibSp"] + df["Parch"]) >= 1, "Has Family", "No Family")
        return df.groupby(family)["Survived"].mean()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Survived": [0, 1, 1, 1, 0],
                    "SibSp": [1, 1, 0, 1, 0],
                    "Parch": [0, 0, 0, 0, 1],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Survived": [1, 0, 0, 0, 1],
                    "SibSp": [0, 0, 1, 0, 1],
                    "Parch": [1, 1, 1, 1, 0],
                }
            )
        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, atol=1e-02)
        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

data = np.array([[0, 1, 0],
                 [1, 1, 0],
                 [1, 0, 0],
                 [1, 1, 0],
                 [0, 0, 1]])

result = ... # put solution in this variable

import numpy as np

def g(data):
    family = np.where((data[:, 0] + data[:, 2]) >= 1, 'Has Family', 'No Family')
    unique_groups = np.unique(family)
    means = {}
    for group in unique_groups:
        means[group] = data[family == group, 1].mean()
    return means

result = g(data)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        family = np.where((data[:, 0] + data[:, 2]) >= 1, 'Has Family', 'No Family')
        unique_groups = np.unique(family)
        means = {}
        for group in unique_groups:
            means[group] = data[family == group, 1].mean()
        return means

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [0, 1, 0],
                [1, 1, 0],
                [1, 0, 0],
                [1, 1, 0],
                [0, 0, 1],
            ])
        if test_case_id == 2:
            data = np.array([
                [1, 0, 1],
                [0, 0, 1],
                [0, 1, 1],
                [0, 0, 1],
                [1, 1, 0],
            ])
        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 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)

import numpy as np
def g(df):
    family = np.where((df['Survived'] + df['Parch']) >= 1 , 'Has Family', 'No Family')
    return df.groupby(family)['SibSp'].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
        family = np.where(
            (df["Survived"] + df["Parch"]) >= 1, "Has Family", "No Family"
        )
        return df.groupby(family)["SibSp"].mean()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Survived": [0, 1, 1, 1, 0],
                    "SibSp": [1, 1, 0, 1, 0],
                    "Parch": [0, 0, 0, 0, 1],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Survived": [1, 0, 0, 0, 1],
                    "SibSp": [0, 0, 1, 0, 1],
                    "Parch": [1, 1, 1, 1, 0],
                }
            )
        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, atol=1e-02)
        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([[0, 1, 0],
                 [1, 1, 0],
                 [1, 0, 0],
                 [1, 1, 1],
                 [0, 0, 1]])

result = ... # put solution in this variable

def g(arr):
    family = []
    for i in range(arr.shape[0]):
        if arr[i, 1] == 0 and arr[i, 2] == 0:
            family.append('No Family')
        elif arr[i, 1] == 1 and arr[i, 2] == 1:
            family.append('Has Family')
        elif arr[i, 1] == 0 and arr[i, 2] == 1:
            family.append('New Family')
        else:
            family.append('Old Family')
    unique_families = np.unique(family)
    means = {}
    for uf in unique_families:
        indices = [i for i, x in enumerate(family) if x == uf]
        means[uf] = np.mean(arr[indices, 0])
    return means

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        family = []
        for i in range(arr.shape[0]):
            if arr[i, 1] == 0 and arr[i, 2] == 0:
                family.append('No Family')
            elif arr[i, 1] == 1 and arr[i, 2] == 1:
                family.append('Has Family')
            elif arr[i, 1] == 0 and arr[i, 2] == 1:
                family.append('New Family')
            else:
                family.append('Old Family')
        unique_families = np.unique(family)
        means = {}
        for uf in unique_families:
            indices = [i for i, x in enumerate(family) if x == uf]
            means[uf] = np.mean(arr[indices, 0])
        return means

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [0, 1, 0],
                [1, 1, 0],
                [1, 0, 0],
                [1, 1, 1],
                [0, 0, 1],
            ])
        if test_case_id == 2:
            arr = np.array([
                [1, 0, 1],
                [0, 0, 1],
                [0, 1, 1],
                [0, 0, 1],
                [1, 1, 0],
            ])
        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)

def g(df):
    family = []
    for i in range(len(df)):
        if df.loc[i, 'SibSp'] == 0 and df.loc[i, 'Parch'] == 0:
            family.append('No Family')
        elif df.loc[i, 'SibSp'] == 1 and df.loc[i, 'Parch'] == 1:
            family.append('Has Family')
        elif df.loc[i, 'SibSp'] == 0 and df.loc[i, 'Parch'] == 1:
            family.append('New Family')
        else:
            family.append('Old Family')
    return df.groupby(family)['Survived'].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
        family = []
        for i in range(len(df)):
            if df.loc[i, "SibSp"] == 0 and df.loc[i, "Parch"] == 0:
                family.append("No Family")
            elif df.loc[i, "SibSp"] == 1 and df.loc[i, "Parch"] == 1:
                family.append("Has Family")
            elif df.loc[i, "SibSp"] == 0 and df.loc[i, "Parch"] == 1:
                family.append("New Family")
            else:
                family.append("Old Family")
        return df.groupby(family)["Survived"].mean()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Survived": [0, 1, 1, 1, 0],
                    "SibSp": [1, 1, 0, 1, 0],
                    "Parch": [0, 0, 0, 0, 1],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Survived": [1, 0, 0, 0, 1],
                    "SibSp": [0, 0, 1, 0, 1],
                    "Parch": [1, 1, 1, 1, 0],
                }
            )
        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, atol=1e-02)
        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(arr):
    unique_keys = np.unique(arr['cokey'])
    sorted_arr = np.concatenate([
        arr[arr['cokey'] == key][np.argsort(arr[arr['cokey'] == key]['A'])]
        for key in unique_keys
    ])
    return sorted_arr

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        unique_keys = np.unique(arr['cokey'])
        sorted_arr = np.concatenate([
            arr[arr['cokey'] == key][np.argsort(arr[arr['cokey'] == key]['A'])]
            for key in unique_keys
        ])
        return sorted_arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(
                [(11168155, 18, 56), (11168155, 0, 18), (11168155, 56, 96), (11168156, 96, 152), (11168156, 0, 96)],
                dtype=[('cokey', 'i4'), ('A', 'i4'), ('B', 'i4')]
            )
        if test_case_id == 2:
            arr = np.array(
                [(155, 18, 56), (155, 0, 18), (155, 56, 96), (156, 96, 152), (156, 0, 96)],
                dtype=[('cokey', 'i4'), ('A', 'i4'), ('B', 'i4')]
            )
        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 np.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 g(df):
    return df.groupby('cokey').apply(pd.DataFrame.sort_values, 'A')

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("cokey").apply(pd.DataFrame.sort_values, "A")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "cokey": [11168155, 11168155, 11168155, 11168156, 11168156],
                    "A": [18, 0, 56, 96, 0],
                    "B": [56, 18, 96, 152, 96],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "cokey": [155, 155, 155, 156, 156],
                    "A": [18, 0, 56, 96, 0],
                    "B": [56, 18, 96, 152, 96],
                }
            )
        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 transform_data(data, columns):
    sorted_indices = np.argsort(columns, order=['Caps', 'Middle', 'Lower'])
    sorted_data = data[:, sorted_indices]
    sorted_columns = columns[sorted_indices]
    return sorted_data, sorted_columns

sorted_data, sorted_columns = transform_data(data, columns)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, columns):
        sorted_indices = np.argsort(columns, order=['Caps', 'Middle', 'Lower'])
        sorted_data = data[:, sorted_indices]
        sorted_columns = columns[sorted_indices]
        return sorted_data, sorted_columns

    def define_test_input(test_case_id):
        if test_case_id == 1:
            l = [
                ('A', 'a', '1'),
                ('A', 'b', '2'),
                ('B', 'a', '1'),
                ('A', 'b', '1'),
                ('B', 'b', '1'),
                ('A', 'a', '2'),
            ]
            np.random.seed(1)
            data = np.random.randn(5, 6)
            columns = np.array(l, dtype=[('Caps', 'U1'), ('Middle', 'U1'), ('Lower', 'U1')])
        return data, columns

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

def exec_test(result, expected_result):
    try:
        np.testing.assert_array_almost_equal(result[0], expected_result[0])
        assert np.array_equal(result[1], expected_result[1])
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data, columns = test_input
[insert]
result = (sorted_data, sorted_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
import numpy as np

l = [('A', 'a', '1'), ('A', 'b', '2'), ('B','a', '1'), ('A', 'b', '1'),  ('B','b', '1'),  ('A', 'a', '2')]
np.random.seed(1)
df = pd.DataFrame(np.random.randn(5, 6), columns=l)

df = ... # put solution in this variable

def g(df):
    df=df[sorted(df.columns.to_list())]
    df.columns = pd.MultiIndex.from_tuples(df.columns, names=['Caps','Middle','Lower'])
    return df

df = g(df.copy())

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[sorted(df.columns.to_list())]
        df.columns = pd.MultiIndex.from_tuples(
            df.columns, names=["Caps", "Middle", "Lower"]
        )
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            l = [
                ("A", "a", "1"),
                ("A", "b", "2"),
                ("B", "a", "1"),
                ("A", "b", "1"),
                ("B", "b", "1"),
                ("A", "a", "2"),
            ]
            np.random.seed(1)
            df = pd.DataFrame(np.random.randn(5, 6), columns=l)
        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(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
np.random.seed(123)
birds=np.random.choice(['African Swallow','Dead Parrot','Exploding Penguin'], size=int(5e4))
someTuple=np.unique(birds, return_counts=True)

import numpy as np

np.random.seed(123)
birds = np.random.choice(['African Swallow', 'Dead Parrot', 'Exploding Penguin'], size=int(5e4))
someTuple = np.unique(birds, return_counts=True)

result = ... # put solution in this variable

def g(someTuple):
    return np.column_stack(someTuple)

result = g(someTuple)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        someTuple = data
        return np.column_stack(someTuple)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(123)
            birds = np.random.choice(
                ['African Swallow', 'Dead Parrot', 'Exploding Penguin'], size=int(5e4)
            )
            someTuple = np.unique(birds, return_counts=True)
        return someTuple

    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
someTuple = 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)

someTuple = (array(['African Swallow', 'Dead Parrot', 'Exploding Penguin'], dtype='<U17'), array([16510, 16570, 16920], dtype=int64))

import numpy as np
import pandas as pd

np.random.seed(123)
birds = np.random.choice(['African Swallow', 'Dead Parrot', 'Exploding Penguin'], size=int(5e4))
someTuple = np.unique(birds, return_counts=True)

result = ... # put solution in this variable

def g(someTuple):
    return pd.DataFrame(np.column_stack(someTuple),columns=['birdType','birdCount'])

result = g(someTuple)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        someTuple = data
        return pd.DataFrame(
            np.column_stack(someTuple), columns=["birdType", "birdCount"]
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(123)
            birds = np.random.choice(
                ["African Swallow", "Dead Parrot", "Exploding Penguin"], size=int(5e4)
            )
            someTuple = np.unique(birds, return_counts=True)
        return someTuple

    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
someTuple = 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(data):
    unique_a = np.unique(data[:, 0])
    result = []
    for a in unique_a:
        group = data[data[:, 0] == a, 1]
        mean = np.mean(group)
        std = np.std(group)
        result.append([a, mean, std])
    return np.array(result)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_a = np.unique(data[:, 0])
        result = []
        for a in unique_a:
            group = data[data[:, 0] == a, 1]
            mean = np.mean(group)
            std = np.std(group)
            result.append([a, mean, std])
        return np.array(result)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [1, 12], [1, 13], [1, 23],
                [2, 22], [2, 23], [2, 24],
                [3, 30], [3, 35], [3, 55]
            ])
        if test_case_id == 2:
            data = np.array([
                [4, 12], [4, 13], [4, 23],
                [5, 22], [5, 23], [5, 24],
                [6, 30], [6, 35], [6, 55]
            ])
        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_almost_equal(result, ans, decimal=6)
        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)

import numpy as np
def g(df):
    return df.groupby("a")["b"].agg([np.mean, np.std])

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("a")["b"].agg([np.mean, np.std])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "a": [1, 1, 1, 2, 2, 2, 3, 3, 3],
                    "b": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "a": [4, 4, 4, 5, 5, 5, 6, 6, 6],
                    "b": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                }
            )
        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 g(arr):
    unique_groups = np.unique(arr[:, 1])
    result = {}
    for group in unique_groups:
        group_data = arr[arr[:, 1] == group][:, 0]
        mean = np.mean(group_data)
        std = np.std(group_data)
        result[group] = (mean, std)
    return result

result = g(arr)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_groups = np.unique(data[:, 1])
        result = {}
        for group in unique_groups:
            group_data = data[data[:, 1] == group][:, 0]
            mean = np.mean(group_data)
            std = np.std(group_data)
            result[group] = (mean, std)
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [12, 1], [13, 1], [23, 1],
                [22, 2], [23, 2], [24, 2],
                [30, 3], [35, 3], [55, 3]
            ])
        if test_case_id == 2:
            arr = np.array([
                [12, 4], [13, 4], [23, 4],
                [22, 5], [23, 5], [24, 5],
                [30, 6], [35, 6], [55, 6]
            ])
        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)

import numpy as np
def g(df):
    return df.groupby("b")["a"].agg([np.mean, np.std])

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("b")["a"].agg([np.mean, np.std])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "a": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                    "b": [1, 1, 1, 2, 2, 2, 3, 3, 3],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "a": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                    "b": [4, 4, 4, 5, 5, 5, 6, 6, 6],
                }
            )
        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

def g(arr):
    softmax = np.zeros(arr.shape[0])
    min_max = np.zeros(arr.shape[0])
    for i in range(arr.shape[0]):
        Min = np.inf
        Max = -np.inf
        exp_Sum = 0
        for j in range(arr.shape[0]):
            if arr[i, 0] == arr[j, 0]:
                Min = min(Min, arr[j, 1])
                Max = max(Max, arr[j, 1])
                exp_Sum += np.exp(arr[j, 1])
        softmax[i] = np.exp(arr[i, 1]) / exp_Sum
        min_max[i] = (arr[i, 1] - Min) / (Max - Min)
    result = np.hstack((arr, softmax[:, np.newaxis], min_max[:, np.newaxis]))
    return result

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        softmax = np.zeros(arr.shape[0])
        min_max = np.zeros(arr.shape[0])
        for i in range(arr.shape[0]):
            Min = np.inf
            Max = -np.inf
            exp_Sum = 0
            for j in range(arr.shape[0]):
                if arr[i, 0] == arr[j, 0]:
                    Min = min(Min, arr[j, 1])
                    Max = max(Max, arr[j, 1])
                    exp_Sum += np.exp(arr[j, 1])
            softmax[i] = np.exp(arr[i, 1]) / exp_Sum
            min_max[i] = (arr[i, 1] - Min) / (Max - Min)
        result = np.hstack((arr, softmax[:, np.newaxis], min_max[:, np.newaxis]))
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 12], [1, 13], [1, 23],
                [2, 22], [2, 23], [2, 24],
                [3, 30], [3, 35], [3, 55]
            ])
        if test_case_id == 2:
            arr = np.array([
                [4, 12], [4, 13], [4, 23],
                [5, 22], [5, 23], [5, 24],
                [6, 30], [6, 35], [6, 55]
            ])
        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, decimal=6)
        return 1
    except:
        return 0

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

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 g(df):
    softmax = []
    min_max = []
    for i in range(len(df)):
        Min = np.inf
        Max = -np.inf
        exp_Sum = 0
        for j in range(len(df)):
            if df.loc[i, 'a'] == df.loc[j, 'a']:
                Min = min(Min, df.loc[j, 'b'])
                Max = max(Max, df.loc[j, 'b'])
                exp_Sum += np.exp(df.loc[j, 'b'])
        softmax.append(np.exp(df.loc[i, 'b']) / exp_Sum)
        min_max.append((df.loc[i, 'b'] - Min) / (Max - Min))
    df['softmax'] = softmax
    df['min-max'] = min_max
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        softmax = []
        min_max = []
        for i in range(len(df)):
            Min = np.inf
            Max = -np.inf
            exp_Sum = 0
            for j in range(len(df)):
                if df.loc[i, "a"] == df.loc[j, "a"]:
                    Min = min(Min, df.loc[j, "b"])
                    Max = max(Max, df.loc[j, "b"])
                    exp_Sum += np.exp(df.loc[j, "b"])
            softmax.append(np.exp(df.loc[i, "b"]) / exp_Sum)
            min_max.append((df.loc[i, "b"] - Min) / (Max - Min))
        df["softmax"] = softmax
        df["min-max"] = min_max
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "a": [1, 1, 1, 2, 2, 2, 3, 3, 3],
                    "b": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "a": [4, 4, 4, 5, 5, 5, 6, 6, 6],
                    "b": [12, 13, 23, 22, 23, 24, 30, 35, 55],
                }
            )
        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)


def g(array):
    row_mask = np.max(array, axis=1) != 2
    col_mask = np.max(array, axis=0) != 2
    return array[np.ix_(row_mask, col_mask)]

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        row_mask = np.max(array, axis=1) != 2
        col_mask = np.max(array, axis=0) != 2
        return array[np.ix_(row_mask, col_mask)]

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

    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
array = 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.loc[(df.max(axis=1) != 2), (df.max(axis=0) != 2)]

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.loc[(df.max(axis=1) != 2), (df.max(axis=0) != 2)]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                [[1, 2, 3, 1], [0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 2, 0], [1, 1, 0, 1]],
                columns=["A", "B", "C", "D"],
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                [[1, 1, 3, 1], [0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 2, 0], [1, 1, 0, 1]],
                columns=["A", "B", "C", "D"],
            )
        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 g(array):
    rows = np.max(array, axis=1) == 2
    cols = np.max(array, axis=0) == 2
    array[rows, :] = 0
    array[:, cols] = 0
    return array

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        rows = np.max(array, axis=1) == 2
        cols = np.max(array, axis=0) == 2
        array[rows, :] = 0
        array[:, cols] = 0
        return array

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

    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
array = 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):
    rows = df.max(axis=1) == 2
    cols = df.max(axis=0) == 2
    df.loc[rows] = 0
    df.loc[:,cols] = 0
    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
        rows = df.max(axis=1) == 2
        cols = df.max(axis=0) == 2
        df.loc[rows] = 0
        df.loc[:, cols] = 0
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                [[1, 2, 1, 1], [0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 2, 0], [1, 1, 0, 1]],
                columns=["A", "B", "C", "D"],
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 2, 0], [1, 1, 0, 1]],
                columns=["A", "B", "C", "D"],
            )
        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

def g(s):
    return np.sort(s, order=['value', 'index'])

result = g(s.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        s = data
        return np.sort(s, order=['value', 'index'])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = np.array([
                ('146tf150p', 1.0), ('havent', 1.0), ('home', 1.0), ('okie', 1.0), ('thanx', 1.0), ('er', 1.0), ('anything', 1.0), ('lei', 1.0), ('nite', 1.0), ('yup', 1.0), ('thank', 1.0), ('ok', 1.0), ('where', 1.0), ('beerage', 1.0), ('anytime', 1.0), ('too', 1.0), ('done', 1.0), ('645', 1.0), ('tick', 0.980166), ('blank', 0.932702)
            ], dtype=[('index', 'U10'), ('value', 'f4')])
        if test_case_id == 2:
            s = np.array([
                ('146tf150p', 1.0), ('havent', 1.0), ('homo', 1.0), ('okie', 1.0), ('thanx', 1.0), ('er', 1.0), ('anything', 1.0), ('lei', 1.0), ('nite', 0.86), ('yup', 1.0), ('thank', 1.0), ('ok', 1.0), ('where', 1.0), ('beerage', 1.0), ('anytime', 1.0), ('too', 1.0), ('done', 1.0), ('645', 1.0), ('tick', 0.980166), ('blank', 0.932702)
            ], dtype=[('index', 'U10'), ('value', 'f4')])
        return s

    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
s = 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

s = pd.Series([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0.98,0.93],
          index=['146tf150p','havent','home','okie','thanx','er','anything','lei','nite','yup','thank','ok','where','beerage','anytime','too','done','645','tick','blank'])

result = ... # put solution in this variable

import numpy as np
def g(s):
    return s.iloc[np.lexsort([s.index, s.values])]

result = g(s.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        s = data
        return s.iloc[np.lexsort([s.index, s.values])]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series(
                [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93],
                index=[
                    "146tf150p",
                    "havent",
                    "home",
                    "okie",
                    "thanx",
                    "er",
                    "anything",
                    "lei",
                    "nite",
                    "yup",
                    "thank",
                    "ok",
                    "where",
                    "beerage",
                    "anytime",
                    "too",
                    "done",
                    "645",
                    "tick",
                    "blank",
                ],
            )
        if test_case_id == 2:
            s = pd.Series(
                [1, 1, 1, 1, 1, 1, 1, 0.86, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93],
                index=[
                    "146tf150p",
                    "havent",
                    "homo",
                    "okie",
                    "thanx",
                    "er",
                    "anything",
                    "lei",
                    "nite",
                    "yup",
                    "thank",
                    "ok",
                    "where",
                    "beerage",
                    "anytime",
                    "too",
                    "done",
                    "645",
                    "tick",
                    "blank",
                ],
            )
        return s

    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
s = 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([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93])
indices = np.array(['146tf150p', 'havent', 'home', 'okie', 'thanx', 'er', 'anything', 'lei', 'nite', 'yup', 'thank', 'ok', 'where', 'beerage', 'anytime', 'too', 'done', '645', 'tick', 'blank'])

result = ... # put solution in this variable

import numpy as np
def g(values, indices):
    sorted_indices = np.lexsort((indices, values))
    sorted_values = values[sorted_indices]
    sorted_indices = indices[sorted_indices]
    result = np.array(list(zip(sorted_indices, sorted_values)), dtype=[('index', 'U10'), ('value', 'f8')])
    return result

result = g(values.copy(), indices.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(values, indices):
        sorted_indices = np.lexsort((indices, values))
        sorted_values = values[sorted_indices]
        sorted_indices = indices[sorted_indices]
        result = np.array(list(zip(sorted_indices, sorted_values)), dtype=[('index', 'U10'), ('value', 'f8')])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            values = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93])
            indices = np.array(['146tf150p', 'havent', 'home', 'okie', 'thanx', 'er', 'anything', 'lei', 'nite', 'yup', 'thank', 'ok', 'where', 'beerage', 'anytime', 'too', 'done', '645', 'tick', 'blank'])
        if test_case_id == 2:
            values = np.array([1, 1, 1, 1, 1, 1, 1, 0.86, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93])
            indices = np.array(['146tf150p', 'havent', 'homo', 'okie', 'thanx', 'er', 'anything', 'lei', 'nite', 'yup', 'thank', 'ok', 'where', 'beerage', 'anytime', 'too', 'done', '645', 'tick', 'blank'])
        return values, indices

    test_input_values, test_input_indices = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input_values), copy.deepcopy(test_input_indices))
    return (test_input_values, test_input_indices), 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
values, indices = test_input
[insert]
result = result
"""

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

s = pd.Series([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0.98,0.93],
              index=['146tf150p','havent','home','okie','thanx','er','anything','lei','nite','yup','thank','ok','where','beerage','anytime','too','done','645','tick','blank'])

df = ... # put solution in this variable

import numpy as np
def g(s):
    result = s.iloc[np.lexsort([s.index, s.values])].reset_index(drop=False)
    result.columns = ['index',1]
    return result

df = g(s.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        s = data
        result = s.iloc[np.lexsort([s.index, s.values])].reset_index(drop=False)
        result.columns = ["index", 1]
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series(
                [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93],
                index=[
                    "146tf150p",
                    "havent",
                    "home",
                    "okie",
                    "thanx",
                    "er",
                    "anything",
                    "lei",
                    "nite",
                    "yup",
                    "thank",
                    "ok",
                    "where",
                    "beerage",
                    "anytime",
                    "too",
                    "done",
                    "645",
                    "tick",
                    "blank",
                ],
            )
        if test_case_id == 2:
            s = pd.Series(
                [1, 1, 1, 1, 1, 1, 1, 0.86, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98, 0.93],
                index=[
                    "146tf150p",
                    "havent",
                    "homo",
                    "okie",
                    "thanx",
                    "er",
                    "anything",
                    "lei",
                    "nite",
                    "yup",
                    "thank",
                    "ok",
                    "where",
                    "beerage",
                    "anytime",
                    "too",
                    "done",
                    "645",
                    "tick",
                    "blank",
                ],
            )
        return s

    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
s = 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)