import numpy as np

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

arr = ... # put solution in this variable

def fill_nan(arr):
    nan_indices = np.where(np.isnan(arr))[0]
    total_nan_len = len(nan_indices)
    first_nan = total_nan_len // 2
    arr[nan_indices[0:first_nan]] = 0
    arr[nan_indices[first_nan:total_nan_len]] = 1
    return arr

arr = fill_nan(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        nan_indices = np.where(np.isnan(arr))[0]
        total_nan_len = len(nan_indices)
        first_nan = total_nan_len // 2
        arr[nan_indices[0:first_nan]] = 0
        arr[nan_indices[first_nan:total_nan_len]] = 1
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
            ])
        if test_case_id == 2:
            arr = np.array([
                0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
            ])
        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(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np

df = pd.DataFrame({'Column_x': [0,0,0,0,0,0,1,1,1,1,1,1,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan]})

df = ... # put solution in this variable

def g(df):
    idx = df['Column_x'].index[df['Column_x'].isnull()]
    total_nan_len = len(idx)
    first_nan = total_nan_len // 2
    df.loc[idx[0:first_nan], 'Column_x'] = 0
    df.loc[idx[first_nan:total_nan_len], 'Column_x'] = 1
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        idx = df["Column_x"].index[df["Column_x"].isnull()]
        total_nan_len = len(idx)
        first_nan = total_nan_len // 2
        df.loc[idx[0:first_nan], "Column_x"] = 0
        df.loc[idx[first_nan:total_nan_len], "Column_x"] = 1
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Column_x": [
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                    ]
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Column_x": [
                        0,
                        0,
                        0,
                        0,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        1,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                        np.nan,
                    ]
                }
            )
        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 fill_nan(arr):
    nan_indices = np.where(np.isnan(arr))[0]
    total_nan_len = len(nan_indices)
    first_nan = (total_nan_len * 3) // 10
    middle_nan = (total_nan_len * 3) // 10
    arr[nan_indices[0:first_nan]] = 0
    arr[nan_indices[first_nan:first_nan + middle_nan]] = 0.5
    arr[nan_indices[first_nan + middle_nan:total_nan_len]] = 1
    return arr

arr = fill_nan(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        nan_indices = np.where(np.isnan(arr))[0]
        total_nan_len = len(nan_indices)
        first_nan = (total_nan_len * 3) // 10
        middle_nan = (total_nan_len * 3) // 10
        arr[nan_indices[0:first_nan]] = 0
        arr[nan_indices[first_nan:first_nan + middle_nan]] = 0.5
        arr[nan_indices[first_nan + middle_nan:total_nan_len]] = 1
        return arr

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

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

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

exec_context = r"""
import numpy as np
arr = test_input
[insert]
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)

def g(df):
    idx = df['Column_x'].index[df['Column_x'].isnull()]
    total_nan_len = len(idx)
    first_nan = (total_nan_len * 3) // 10
    middle_nan = (total_nan_len * 3) // 10
    df.loc[idx[0:first_nan], 'Column_x'] = 0
    df.loc[idx[first_nan:first_nan + middle_nan], 'Column_x'] = 0.5
    df.loc[idx[first_nan + middle_nan:total_nan_len], 'Column_x'] = 1
    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
        idx = df["Column_x"].index[df["Column_x"].isnull()]
        total_nan_len = len(idx)
        first_nan = (total_nan_len * 3) // 10
        middle_nan = (total_nan_len * 3) // 10
        df.loc[idx[0:first_nan], "Column_x"] = 0
        df.loc[idx[first_nan : first_nan + middle_nan], "Column_x"] = 0.5
        df.loc[idx[first_nan + middle_nan : total_nan_len], "Column_x"] = 1
        return df

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

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

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

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

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


import numpy as np

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

arr = ... # put solution in this variable

def fill_nan(arr):
    total_len = len(arr)
    zero_len = np.sum(arr == 0)
    nan_indices = np.where(np.isnan(arr))[0]
    total_nan_len = len(nan_indices)
    first_nan = (total_len // 2) - zero_len
    arr[nan_indices[0:first_nan]] = 0
    arr[nan_indices[first_nan:total_nan_len]] = 1
    return arr

arr = fill_nan(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        total_len = len(arr)
        zero_len = np.sum(arr == 0)
        nan_indices = np.where(np.isnan(arr))[0]
        total_nan_len = len(nan_indices)
        first_nan = (total_len // 2) - zero_len
        arr[nan_indices[0:first_nan]] = 0
        arr[nan_indices[first_nan:total_nan_len]] = 1
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
            ])
        if test_case_id == 2:
            arr = np.array([
                0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
            ])
        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(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np

df = pd.DataFrame({'Column_x': [0,0,0,0,1,1,1,1,1,1,1,1,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan]})

df = ... # put solution in this variable

def g(df):
    total_len = len(df)
    zero_len = (df['Column_x'] == 0).sum()
    idx = df['Column_x'].index[df['Column_x'].isnull()]
    total_nan_len = len(idx)
    first_nan = (total_len // 2) - zero_len
    df.loc[idx[0:first_nan], 'Column_x'] = 0
    df.loc[idx[first_nan:total_nan_len], 'Column_x'] = 1
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        total_len = len(df)
        zero_len = (df["Column_x"] == 0).sum()
        idx = df["Column_x"].index[df["Column_x"].isnull()]
        total_nan_len = len(idx)
        first_nan = (total_len // 2) - zero_len
        df.loc[idx[0:first_nan], "Column_x"] = 0
        df.loc[idx[first_nan:total_nan_len], "Column_x"] = 1
        return df

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

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

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

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

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


import numpy as np

a = np.array([[1, 2],[3, 4]])
b = np.array([[5, 6],[7, 8]])
c = np.array([[9, 10],[11, 12]])

result = ... # put solution in this variable

def g(a, b, c):
    return np.array(list(map(list, zip(a, b, c))))

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

import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        a, b, c = data
        return np.array(list(map(list, zip(a, b, c))))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[1, 2], [3, 4]])
            b = np.array([[5, 6], [7, 8]])
            c = np.array([[9, 10], [11, 12]])
        if test_case_id == 2:
            b = np.array([[1, 2], [3, 4]])
            c = np.array([[5, 6], [7, 8]])
            a = np.array([[9, 10], [11, 12]])
        return a, b, c

    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
a, b, c = test_input
[insert]
"""

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

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

import pandas as pd
import numpy as np

a = pd.DataFrame(np.array([[1, 2],[3, 4]]), columns=['one', 'two'])
b = pd.DataFrame(np.array([[5, 6],[7, 8]]), columns=['one', 'two'])
c = pd.DataFrame(np.array([[9, 10],[11, 12]]), columns=['one', 'two'])

result = ... # put solution in this variable

def g(a,b,c):
    return pd.DataFrame(np.rec.fromarrays((a.values, b.values, c.values)).tolist(),columns=a.columns,index=a.index)

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

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

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        a, b, c = data
        return pd.DataFrame(
            np.rec.fromarrays((a.values, b.values, c.values)).tolist(),
            columns=a.columns,
            index=a.index,
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = pd.DataFrame(np.array([[1, 2], [3, 4]]), columns=["one", "two"])
            b = pd.DataFrame(np.array([[5, 6], [7, 8]]), columns=["one", "two"])
            c = pd.DataFrame(np.array([[9, 10], [11, 12]]), columns=["one", "two"])
        if test_case_id == 2:
            b = pd.DataFrame(np.array([[1, 2], [3, 4]]), columns=["one", "two"])
            c = pd.DataFrame(np.array([[5, 6], [7, 8]]), columns=["one", "two"])
            a = pd.DataFrame(np.array([[9, 10], [11, 12]]), columns=["one", "two"])
        return a, b, c

    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
a,b,c = test_input
[insert]
"""

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

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


import numpy as np

username = np.array(['john', 'john', 'john', 'john', 'jane', 'jane', 'jane', 'jane'])
post_id = np.array([1, 2, 3, 4, 7, 8, 9, 10])
views = np.array([3, 23, 44, 82, 5, 25, 46, 56])
bins = [1, 10, 25, 50, 100]

result = ... # put solution in this variable

def g(username, views, bins):
    bin_indices = np.digitize(views, bins, right=True)
    unique_users = np.unique(username)
    result = np.zeros((len(unique_users), len(bins) - 1), dtype=int)
    for i, user in enumerate(unique_users):
        user_views = views[username == user]
        user_bins = bin_indices[username == user]
        for j in range(1, len(bins)):
            result[i, j - 1] = np.sum(user_bins == j)
    return result

result = g(username, views, bins)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        username, views, bins = data
        bin_indices = np.digitize(views, bins, right=True)
        unique_users = np.unique(username)
        result = np.zeros((len(unique_users), len(bins) - 1), dtype=int)
        for i, user in enumerate(unique_users):
            user_views = views[username == user]
            user_bins = bin_indices[username == user]
            for j in range(1, len(bins)):
                result[i, j - 1] = np.sum(user_bins == j)
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            username = np.array(['john', 'john', 'john', 'john', 'jane', 'jane', 'jane', 'jane'])
            views = np.array([3, 23, 44, 82, 5, 25, 46, 56])
            bins = [1, 10, 25, 50, 100]
        if test_case_id == 2:
            username = np.array(['john', 'john', 'john', 'john', 'jane', 'jane', 'jane', 'jane'])
            views = np.array([3, 23, 44, 82, 5, 25, 46, 56])
            bins = [1, 5, 25, 50, 100]
        return username, views, bins

    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
username, views, bins = 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({'username': ['john', 'john', 'john', 'john', 'jane', 'jane', 'jane', 'jane'],
                   'post_id': [1, 2, 3, 4, 7, 8, 9, 10],
                   'views': [3, 23, 44, 82, 5, 25,46, 56]})
bins = [1, 10, 25, 50, 100]

result = ... # put solution in this variable

def g(df, bins):
    groups = df.groupby(['username', pd.cut(df.views, bins)])
    return groups.size().unstack()

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, bins = data
        groups = df.groupby(["username", pd.cut(df.views, bins)])
        return groups.size().unstack()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "username": [
                        "john",
                        "john",
                        "john",
                        "john",
                        "jane",
                        "jane",
                        "jane",
                        "jane",
                    ],
                    "post_id": [1, 2, 3, 4, 7, 8, 9, 10],
                    "views": [3, 23, 44, 82, 5, 25, 46, 56],
                }
            )
            bins = [1, 10, 25, 50, 100]
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "username": [
                        "john",
                        "john",
                        "john",
                        "john",
                        "jane",
                        "jane",
                        "jane",
                        "jane",
                    ],
                    "post_id": [1, 2, 3, 4, 7, 8, 9, 10],
                    "views": [3, 23, 44, 82, 5, 25, 46, 56],
                }
            )
            bins = [1, 5, 25, 50, 100]
        return df, bins

    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, bins = 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(['abc', 'def', 'ghi', 'jkl'])

result = ... # put solution in this variable

def g(arr):
    return ', '.join(arr[::-1])

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return ', '.join(arr[::-1])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(['abc', 'def', 'ghi', 'jkl'])
        if test_case_id == 2:
            arr = np.array(['abc', 'dgh', 'mni', 'qwe'])
        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)

abc def ghi jkl

import pandas as pd

df = pd.DataFrame({'text': ['abc', 'def', 'ghi', 'jkl']})

result = ... # put solution in this variable

def g(df):
    return pd.DataFrame({'text': [', '.join(df['text'].str.strip('"').tolist()[::-1])]})

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 pd.DataFrame(
            {"text": [", ".join(df["text"].str.strip('"').tolist()[::-1])]}
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"text": ["abc", "def", "ghi", "jkl"]})
        if test_case_id == 2:
            df = pd.DataFrame({"text": ["abc", "dgh", "mni", "qwe"]})
        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(array1, array2):
    id_to_city_district = {row[0]: row[1:3] for row in array1}
    filled_array2 = np.array([
        [row[0], *id_to_city_district.get(row[0], [None, None]), row[1], row[2]]
        for row in array2
    ], dtype=object)
    return np.vstack((array1, filled_array2))

result = g(array1.copy(), array2.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array1, array2 = data
        id_to_city_district = {row[0]: row[1:3] for row in array1}
        filled_array2 = np.array([
            [row[0], *id_to_city_district.get(row[0], [None, None]), row[1], row[2]]
            for row in array2
        ], dtype=object)
        return np.vstack((array1, filled_array2))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array1 = np.array([
                [1, 'bj', 'ft', '2019/1/1', 1],
                [2, 'bj', 'ft', '2019/1/1', 5],
                [3, 'sh', 'hp', '2019/1/1', 9],
                [4, 'sh', 'hp', '2019/1/1', 13],
                [5, 'sh', 'hp', '2019/1/1', 17]
            ], dtype=object)
            array2 = np.array([
                [3, '2019/2/1', 1],
                [4, '2019/2/1', 5],
                [5, '2019/2/1', 9],
                [6, '2019/2/1', 13],
                [7, '2019/2/1', 17]
            ], dtype=object)
        if test_case_id == 2:
            array1 = np.array([
                [1, 'bj', 'ft', '2019/2/1', 1],
                [2, 'bj', 'ft', '2019/2/1', 5],
                [3, 'sh', 'hp', '2019/2/1', 9],
                [4, 'sh', 'hp', '2019/2/1', 13],
                [5, 'sh', 'hp', '2019/2/1', 17]
            ], dtype=object)
            array2 = np.array([
                [3, '2019/3/1', 1],
                [4, '2019/3/1', 5],
                [5, '2019/3/1', 9],
                [6, '2019/3/1', 13],
                [7, '2019/3/1', 17]
            ], dtype=object)
        return array1, array2

    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
array1, array2 = 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(df1, df2):
    return pd.concat([df1,df2.merge(df1[['id','city','district']], how='left', on='id')],sort=False).reset_index(drop=True)

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


def g(array1, array2):
    # Create a dictionary to map id to city and district
    id_map = {row[0]: row[1:3] for row in array1}

    # Fill city and district in array2
    filled_array2 = np.array([
        [row[0], *id_map.get(row[0], [None, None]), row[1], row[2]]
        for row in array2
    ], dtype=object)

    # Concatenate arrays
    combined = np.concatenate((array1, filled_array2), axis=0)

    # Sort by id and date
    sorted_combined = combined[np.lexsort((combined[:, 3], combined[:, 0]))]
    return sorted_combined

result = g(array1.copy(), array2.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array1, array2 = data
        id_map = {row[0]: row[1:3] for row in array1}
        filled_array2 = np.array([
            [row[0], *id_map.get(row[0], [None, None]), row[1], row[2]]
            for row in array2
        ], dtype=object)
        combined = np.concatenate((array1, filled_array2), axis=0)
        sorted_combined = combined[np.lexsort((combined[:, 3], combined[:, 0]))]
        return sorted_combined

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array1 = np.array([
                [1, 'bj', 'ft', '2019/1/1', 1],
                [2, 'bj', 'ft', '2019/1/1', 5],
                [3, 'sh', 'hp', '2019/1/1', 9],
                [4, 'sh', 'hp', '2019/1/1', 13],
                [5, 'sh', 'hp', '2019/1/1', 17]
            ], dtype=object)
            array2 = np.array([
                [3, '2019/2/1', 1],
                [4, '2019/2/1', 5],
                [5, '2019/2/1', 9],
                [6, '2019/2/1', 13],
                [7, '2019/2/1', 17]
            ], dtype=object)
        if test_case_id == 2:
            array1 = np.array([
                [1, 'bj', 'ft', '2019/2/1', 1],
                [2, 'bj', 'ft', '2019/2/1', 5],
                [3, 'sh', 'hp', '2019/2/1', 9],
                [4, 'sh', 'hp', '2019/2/1', 13],
                [5, 'sh', 'hp', '2019/2/1', 17]
            ], dtype=object)
            array2 = np.array([
                [3, '2019/3/1', 1],
                [4, '2019/3/1', 5],
                [5, '2019/3/1', 9],
                [6, '2019/3/1', 13],
                [7, '2019/3/1', 17]
            ], dtype=object)
        return array1, array2

    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
array1, array2 = 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(df1, df2):
    df = pd.concat([df1,df2.merge(df1[['id','city','district']], how='left', on='id')],sort=False).reset_index(drop=True)
    return df.sort_values(by=['id','date']).reset_index(drop=True)

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


import numpy as np

C = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
D = np.array([['CD', 4], ['GH', 5]])

result = ... # put solution in this variable

def g(C, D):
    # Convert to dictionary for easy manipulation
    c_dict = {row[0]: row[1] for row in C}
    d_dict = {row[0]: row[1] for row in D}
    # Update C with values from D
    c_dict.update(d_dict)
    # Create a sorted list of keys
    keys = sorted(c_dict.keys())
    # Construct the result array
    result = np.array([[key, c_dict[key]] for key in keys])
    return result

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        C, D = data
        c_dict = {row[0]: row[1] for row in C}
        d_dict = {row[0]: row[1] for row in D}
        c_dict.update(d_dict)
        keys = sorted(c_dict.keys())
        result = np.array([[key, c_dict[key]] for key in keys])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            D = np.array([['CD', 4], ['GH', 5]])
        if test_case_id == 2:
            D = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            C = np.array([['CD', 4], ['GH', 5]])
        return C, D

    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
C, D = 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

C = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
D = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})

result = ... # put solution in this variable

def g(C, D):
    return pd.concat([C,D]).drop_duplicates('A', keep='last').sort_values(by=['A']).reset_index(drop=True)

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        C, D = data
        return (
            pd.concat([C, D])
            .drop_duplicates("A", keep="last")
            .sort_values(by=["A"])
            .reset_index(drop=True)
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            D = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        if test_case_id == 2:
            D = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            C = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        return C, D

    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
C, D = 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(C, D):
    unique_keys = {}
    for row in np.vstack((C, D)):
        if row[0] not in unique_keys:
            unique_keys[row[0]] = row
    return np.array(list(unique_keys.values()))

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        C, D = data
        unique_keys = {}
        for row in np.vstack((C, D)):
            if row[0] not in unique_keys:
                unique_keys[row[0]] = row
        return np.array(list(unique_keys.values()))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            D = np.array([['CD', 4], ['GH', 5]])
        if test_case_id == 2:
            D = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            C = np.array([['CD', 4], ['GH', 5]])
        return C, D

    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
C, D = 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(C, D):
    return pd.concat([C,D]).drop_duplicates('A', keep='first').sort_values(by=['A']).reset_index(drop=True)

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        C, D = data
        return (
            pd.concat([C, D])
            .drop_duplicates("A", keep="first")
            .sort_values(by=["A"])
            .reset_index(drop=True)
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            D = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        if test_case_id == 2:
            D = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            C = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        return C, D

    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
C, D = 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(C, D):
    dtype = [('A', 'U2'), ('B', 'i4'), ('duplicated', 'bool')]
    merged = np.concatenate((C, D))
    unique, indices = np.unique(merged[:, 0], return_index=True)
    merged = merged[indices]
    merged = merged[np.argsort(merged[:, 0])]
    result = np.zeros((len(merged),), dtype=dtype)
    result['A'] = merged[:, 0]
    result['B'] = merged[:, 1].astype(int)
    result['duplicated'] = np.isin(result['A'], D[:, 0])
    return result

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        C, D = data
        dtype = [('A', 'U2'), ('B', 'i4'), ('duplicated', 'bool')]
        merged = np.concatenate((C, D))
        unique, indices = np.unique(merged[:, 0], return_index=True)
        merged = merged[indices]
        merged = merged[np.argsort(merged[:, 0])]
        result = np.zeros((len(merged),), dtype=dtype)
        result['A'] = merged[:, 0]
        result['B'] = merged[:, 1].astype(int)
        result['duplicated'] = np.isin(result['A'], D[:, 0])
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            D = np.array([['CD', 4], ['GH', 5]])
        if test_case_id == 2:
            D = np.array([['AB', 1], ['CD', 2], ['EF', 3]])
            C = np.array([['CD', 4], ['GH', 5]])
        return C, D

    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
C, D = 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(C, D):
    df = pd.concat([C,D]).drop_duplicates('A', keep='last').sort_values(by=['A']).reset_index(drop=True)
    for i in range(len(C)):
        if df.loc[i, 'A'] in D.A.values:
            df.loc[i, 'dulplicated'] = True
        else:
            df.loc[i, 'dulplicated'] = False
    for i in range(len(C), len(df)):
        df.loc[i, 'dulplicated'] = False
    return df

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        C, D = data
        df = (
            pd.concat([C, D])
            .drop_duplicates("A", keep="last")
            .sort_values(by=["A"])
            .reset_index(drop=True)
        )
        for i in range(len(C)):
            if df.loc[i, "A"] in D.A.values:
                df.loc[i, "dulplicated"] = True
            else:
                df.loc[i, "dulplicated"] = False
        for i in range(len(C), len(df)):
            df.loc[i, "dulplicated"] = False
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            C = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            D = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        if test_case_id == 2:
            D = pd.DataFrame({"A": ["AB", "CD", "EF"], "B": [1, 2, 3]})
            C = pd.DataFrame({"A": ["CD", "GH"], "B": [4, 5]})
        return C, D

    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
C, D = 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([(1, 20, 10.99), (1, 10, 4.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)], dtype=[('user', 'i4'), ('time', 'f4'), ('amount', 'f4')])
### Output your answer into variable 'result'

result = ... # put solution in this variable

def g(data):
    unique_users = np.unique(data['user'])
    return np.array([data[['time', 'amount']][data['user'] == user].tolist() for user in unique_users], dtype=object)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_users = np.unique(data['user'])
        return np.array([data[['time', 'amount']][data['user'] == user].tolist() for user in unique_users], dtype=object)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'f4'), ('amount', 'f4')]
            )
        if test_case_id == 2:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (1, 30, 16.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'f4'), ('amount', 'f4')]
            )
        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)

import pandas as pd

df = pd.DataFrame({'user':[1,1,2,2,3], 'time':[20,10,11,18, 15], 'amount':[10.99, 4.99, 2.99, 1.99, 10.99]})
### Output your answer into variable 'result'

result = ... # put solution in this variable

def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist())

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("user")[["time", "amount"]].apply(lambda x: x.values.tolist())

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 2, 2, 3],
                    "time": [20, 10, 11, 18, 15],
                    "amount": [10.99, 4.99, 2.99, 1.99, 10.99],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 1, 2, 2, 3],
                    "time": [20, 10, 30, 11, 18, 15],
                    "amount": [10.99, 4.99, 16.99, 2.99, 1.99, 10.99],
                }
            )
        return df

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

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

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

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


def g(data):
    users = np.unique(data['user'])
    result = []
    for user in users:
        user_data = data[data['user'] == user]
        sorted_data = np.sort(user_data, order='time')
        result.append(sorted_data[['time', 'amount']].tolist())
    return np.array(result, dtype=object)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        users = np.unique(data['user'])
        result = []
        for user in users:
            user_data = data[data['user'] == user]
            sorted_data = np.sort(user_data, order='time')
            result.append(sorted_data[['time', 'amount']].tolist())
        return np.array(result, dtype=object)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'f4'), ('amount', 'f4')]
            )
        if test_case_id == 2:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (1, 30, 16.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'f4'), ('amount', 'f4')]
            )
        return data

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

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

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

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

def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist()).to_frame(name='amount-time-tuple')

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("user")[["time", "amount"]]
            .apply(lambda x: x.values.tolist())
            .to_frame(name="amount-time-tuple")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 2, 2, 3],
                    "time": [20, 10, 11, 18, 15],
                    "amount": [10.99, 4.99, 2.99, 1.99, 10.99],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 1, 2, 2, 3],
                    "time": [20, 10, 30, 11, 18, 15],
                    "amount": [10.99, 4.99, 16.99, 2.99, 1.99, 10.99],
                }
            )
        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)
        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([(1, 20, 10.99), (1, 10, 4.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)], dtype=[('user', 'i4'), ('time', 'i4'), ('amount', 'f4')])
### Output your answer into variable 'result'

result = ... # put solution in this variable

def g(data):
    users = np.unique(data['user'])
    result = {}
    for user in users:
        user_data = data[data['user'] == user]
        sorted_data = np.sort(user_data, order='time')[::-1]
        result[user] = sorted_data[['time', 'amount']].tolist()
    return result

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        users = np.unique(data['user'])
        result = {}
        for user in users:
            user_data = data[data['user'] == user]
            sorted_data = np.sort(user_data, order='time')[::-1]
            result[user] = sorted_data[['time', 'amount']].tolist()
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'i4'), ('amount', 'f4')]
            )
        if test_case_id == 2:
            data = np.array(
                [(1, 20, 10.99), (1, 10, 4.99), (1, 30, 16.99), (2, 11, 2.99), (2, 18, 1.99), (3, 15, 10.99)],
                dtype=[('user', 'i4'), ('time', 'i4'), ('amount', 'f4')]
            )
        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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.groupby('user')[['time', 'amount']].apply(lambda x: x.values.tolist()[::-1]).to_frame(name='amount-time-tuple')

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("user")[["time", "amount"]]
            .apply(lambda x: x.values.tolist()[::-1])
            .to_frame(name="amount-time-tuple")
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 2, 2, 3],
                    "time": [20, 10, 11, 18, 15],
                    "amount": [10.99, 4.99, 2.99, 1.99, 10.99],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "user": [1, 1, 1, 2, 2, 3],
                    "time": [20, 10, 30, 11, 18, 15],
                    "amount": [10.99, 4.99, 16.99, 2.99, 1.99, 10.99],
                }
            )
        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)
        return 1
    except:
        return 0

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

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


import numpy as np

arrays = np.array([np.array([1,2,3,4]), np.array([5,6,7,8]), np.array([9,10,11,12])])

structured_array = ... # put solution in this variable

def g(arr):
    names = np.array(['file1', 'file2', 'file3'])
    data = np.column_stack((names, arr))
    return data

structured_array = g(arrays.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        names = np.array(['file1', 'file2', 'file3'])
        return np.column_stack((names, data))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arrays = np.array([
                np.array([1, 2, 3, 4]),
                np.array([5, 6, 7, 8]),
                np.array([9, 10, 11, 12]),
            ])
        if test_case_id == 2:
            arrays = np.array([
                np.array([11, 12, 13, 14]),
                np.array([5, 6, 7, 8]),
                np.array([9, 10, 11, 12]),
            ])
        return arrays

    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
arrays = test_input
[insert]
result = structured_array
"""

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

series = pd.Series([np.array([1,2,3,4]), np.array([5,6,7,8]), np.array([9,10,11,12])], index=['file1', 'file2', 'file3'])

df = ... # put solution in this variable

def g(s):
    return pd.DataFrame.from_records(s.values,index=s.index).reset_index().rename(columns={'index': 'name'})

df = g(series.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 (
            pd.DataFrame.from_records(s.values, index=s.index)
            .reset_index()
            .rename(columns={"index": "name"})
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            series = pd.Series(
                [
                    np.array([1, 2, 3, 4]),
                    np.array([5, 6, 7, 8]),
                    np.array([9, 10, 11, 12]),
                ],
                index=["file1", "file2", "file3"],
            )
        if test_case_id == 2:
            series = pd.Series(
                [
                    np.array([11, 12, 13, 14]),
                    np.array([5, 6, 7, 8]),
                    np.array([9, 10, 11, 12]),
                ],
                index=["file1", "file2", "file3"],
            )
        return series

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


column_names = ['spike-2', 'hey spike', 'spiked-in', 'random']

import numpy as np

names = np.array(['spike-2', 'hey spke', 'spiked-in', 'no'])
data = np.array([[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]])
s = 'spike'

result = ... # put solution in this variable

def g(names, s):
    spike_cols = [name for name in names if s in name and name != s]
    return spike_cols

result = g(names.copy(), s)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        names, s = data
        spike_cols = [name for name in names if s in name and name != s]
        return spike_cols

    def define_test_input(test_case_id):
        if test_case_id == 1:
            names = np.array(['spike-2', 'hey spke', 'spiked-in', 'no', 'spike'])
            data = np.array([[1, 4, 7, 10, 13], [2, 5, 8, 11, 14], [3, 6, 9, 12, 15]])
            s = 'spike'
        return names, 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 result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
names, s = test_input
[insert]
"""

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

df.columns = ['spike-2', 'hey spike', 'spiked-in', 'other']

import pandas as pd

data = {'spike-2': [1,2,3], 'hey spke': [4,5,6], 'spiked-in': [7,8,9], 'no': [10,11,12]}
df = pd.DataFrame(data)
s = 'spike'

result = ... # put solution in this variable

def g(df, s):
    spike_cols = [col for col in df.columns if s in col and col != s]
    return spike_cols

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, s = data
        spike_cols = [col for col in df.columns if s in col and col != s]
        return spike_cols

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = {
                "spike-2": [1, 2, 3],
                "hey spke": [4, 5, 6],
                "spiked-in": [7, 8, 9],
                "no": [10, 11, 12],
                "spike": [13, 14, 15],
            }
            df = pd.DataFrame(data)
            s = "spike"
        return df, 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 result == ans
        return 1
    except:
        return 0

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

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


import numpy as np

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

result = ... # put solution in this variable

def g(arr):
    return np.concatenate(arr)

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return np.concatenate(arr)

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

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

def exec_test(result, ans):
    try:
        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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame(dict(col1=[[1, 2, 3]] * 2))

result = ... # put solution in this variable

def g(df):
    return df.col1.sum()

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.col1.sum()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(dict(col1=[[1, 2, 3]] * 2))
        return df

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

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

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

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


def g(arr):
    L = arr.sum(axis=0)
    L = map(lambda x: str(x), L)
    return ','.join(L)

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        L = arr.sum(axis=0)
        L = map(lambda x: str(x), L)
        return ','.join(L)

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

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

def exec_test(result, ans):
    try:
        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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    L = df.col1.sum()
    L = map(lambda x:str(x), L)
    return ','.join(L)

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
        L = df.col1.sum()
        L = map(lambda x: str(x), L)
        return ",".join(L)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(dict(col1=[[1, 2, 3]] * 2))
        return df

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

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

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

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(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 rank_and_format(ids, times):
    # Convert times to datetime objects
    times_dt = np.array([datetime.strptime(t, '%Y-%m-%d %H:%M:%S') for t in times])

    # Format times
    formatted_times = np.array([t.strftime('%d-%b-%Y %a %T') for t in times_dt])

    # Initialize ranks
    ranks = np.zeros(len(times), dtype=int)

    # Rank times within each ID
    unique_ids = np.unique(ids)
    for uid in unique_ids:
        mask = ids == uid
        sorted_indices = np.argsort(times_dt[mask])[::-1]
        ranks[mask] = np.arange(1, np.sum(mask) + 1)[sorted_indices]

    return np.column_stack((ids, formatted_times, ranks))

result = rank_and_format(ids, times)

import numpy as np
from datetime import datetime
import copy

def generate_test_case(test_case_id):
    def generate_ans(ids, times):
        times_dt = np.array([datetime.strptime(t, '%Y-%m-%d %H:%M:%S') for t in times])
        formatted_times = np.array([t.strftime('%d-%b-%Y %a %T') for t in times_dt])
        ranks = np.zeros(len(times), dtype=int)
        unique_ids = np.unique(ids)
        for uid in unique_ids:
            mask = ids == uid
            sorted_indices = np.argsort(times_dt[mask])[::-1]
            ranks[mask] = np.arange(1, np.sum(mask) + 1)[sorted_indices]
        return np.column_stack((ids, formatted_times, ranks))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            ids = np.array(['01', '01', '01', '02', '02'])
            times = np.array([
                '2018-07-11 11:12:20',
                '2018-07-12 12:00:23',
                '2018-07-13 12:00:00',
                '2019-09-11 11:00:00',
                '2019-09-12 12:00:00',
            ])
        return ids, times

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input[0]), copy.deepcopy(test_input[1]))
    return test_input, expected_result

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

exec_context = r'''
import numpy as np
from datetime import datetime
ids, times = test_input
[insert]
result = rank_and_format(ids, times)
'''

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

def g(df):
    df['TIME'] = pd.to_datetime(df['TIME'])
    df['TIME'] = df['TIME'].dt.strftime('%d-%b-%Y %a %T')
    df['RANK'] = df.groupby('ID')['TIME'].rank(ascending=False)
    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["TIME"] = pd.to_datetime(df["TIME"])
        df["TIME"] = df["TIME"].dt.strftime("%d-%b-%Y %a %T")
        df["RANK"] = df.groupby("ID")["TIME"].rank(ascending=False)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "ID": ["01", "01", "01", "02", "02"],
                    "TIME": [
                        "2018-07-11 11:12:20",
                        "2018-07-12 12:00:23",
                        "2018-07-13 12:00:00",
                        "2019-09-11 11:00:00",
                        "2019-09-12 12:00:00",
                    ],
                }
            )
        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

arr = np.array([[1, 1, 1, 2, 2, 2, 3, 3, 3],
                [1, 2, 3, 1, 2, 3, 1, 2, 3],
                range(9)]).T
filt = np.array([True, False, True])

result = ... # put solution in this variable

def g(arr, filt):
    return arr[np.isin(arr[:, 0], np.where(filt)[0] + 1)]

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr, filt = data
        return arr[np.isin(arr[:, 0], np.where(filt)[0] + 1)]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 1, 2, 2, 2, 3, 3, 3],
                [1, 2, 3, 1, 2, 3, 1, 2, 3],
                range(9),
            ]).T
            filt = np.array([True, False, True])
        elif test_case_id == 2:
            arr = np.array([
                [1, 1, 1, 2, 2, 2, 3, 3, 3],
                [1, 2, 3, 1, 2, 3, 1, 2, 3],
                range(9),
            ]).T
            filt = np.array([True, True, False])
        return arr, filt

    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, filt = 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({'a': [1,1,1,2,2,2,3,3,3],
                    'b': [1,2,3,1,2,3,1,2,3],
                    'c': range(9)}).set_index(['a', 'b'])
filt = pd.Series({1:True, 2:False, 3:True})

result = ... # put solution in this variable

def g(df, filt):
    return df[filt[df.index.get_level_values('a')].values]

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, filt = data
        return df[filt[df.index.get_level_values("a")].values]

    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": [1, 2, 3, 1, 2, 3, 1, 2, 3],
                    "c": range(9),
                }
            ).set_index(["a", "b"])
            filt = pd.Series({1: True, 2: False, 3: True})
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "a": [1, 1, 1, 2, 2, 2, 3, 3, 3],
                    "b": [1, 2, 3, 1, 2, 3, 1, 2, 3],
                    "c": range(9),
                }
            ).set_index(["a", "b"])
            filt = pd.Series({1: True, 2: True, 3: False})
        return df, filt

    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, filt = 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, filt):
    mask_a = np.isin(data['a'], np.where(filt)[0] + 1)
    filtered_data = data[mask_a]
    mask_b = np.isin(filtered_data['b'], np.where(filt)[0] + 1)
    return filtered_data[mask_b]

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

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        data, filt = data
        mask_a = np.isin(data['a'], np.where(filt)[0] + 1)
        filtered_data = data[mask_a]
        mask_b = np.isin(filtered_data['b'], np.where(filt)[0] + 1)
        return filtered_data[mask_b]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array(
                [(1, 1, 0), (1, 2, 1), (1, 3, 2), (2, 1, 3), (2, 2, 4), (2, 3, 5), (3, 1, 6), (3, 2, 7), (3, 3, 8)],
                dtype=[('a', int), ('b', int), ('c', int)]
            )
            filt = np.array([True, False, True])
        elif test_case_id == 2:
            data = np.array(
                [(1, 1, 0), (1, 2, 1), (1, 3, 2), (2, 1, 3), (2, 2, 4), (2, 3, 5), (3, 1, 6), (3, 2, 7), (3, 3, 8)],
                dtype=[('a', int), ('b', int), ('c', int)]
            )
            filt = np.array([True, True, False])
        return data, filt

    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, filt = 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, filt):
    df = df[filt[df.index.get_level_values('a')].values]
    return df[filt[df.index.get_level_values('b')].values]

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

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, filt = data
        df = df[filt[df.index.get_level_values("a")].values]
        return df[filt[df.index.get_level_values("b")].values]

    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": [1, 2, 3, 1, 2, 3, 1, 2, 3],
                    "c": range(9),
                }
            ).set_index(["a", "b"])
            filt = pd.Series({1: True, 2: False, 3: True})
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "a": [1, 1, 1, 2, 2, 2, 3, 3, 3],
                    "b": [1, 2, 3, 1, 2, 3, 1, 2, 3],
                    "c": range(9),
                }
            ).set_index(["a", "b"])
            filt = pd.Series({1: True, 2: True, 3: False})
        return df, filt

    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, filt = 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

np.random.seed(10)
array = np.random.randint(0, 20, (10, 10)).astype(float)
mask = np.random.randint(0, 2, array.shape).astype(bool)
array[~mask] = np.nan

result = ... # put solution in this variable

def g(array):
    row0 = np.where(np.isnan(array[0]), 'Nan', array[0])
    row8 = np.where(np.isnan(array[8]), 'Nan', array[8])
    return np.array(['c%d' % i for i in range(array.shape[1])])[row0 != row8]

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        row0 = np.where(np.isnan(array[0]), 'Nan', array[0])
        row8 = np.where(np.isnan(array[8]), 'Nan', array[8])
        return np.array(['c%d' % i for i in range(array.shape[1])])[row0 != row8]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            array = np.random.randint(0, 20, (10, 10)).astype(float)
            mask = np.random.randint(0, 2, array.shape).astype(bool)
            array[~mask] = np.nan
        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(ans, result)
        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(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)

DataFrame with rows 0 and 8 as shown in the question.

import pandas as pd
import numpy as np

np.random.seed(10)
df = pd.DataFrame(np.random.randint(0, 20, (10, 10)).astype(float), columns=["c%d"%d for d in range(10)])
df.where(np.random.randint(0,2, df.shape).astype(bool), np.nan, inplace=True)

result = ... # put solution in this variable

def g(df):
    return df.columns[df.iloc[0,:].fillna('Nan') != df.iloc[8,:].fillna('Nan')]

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.columns[df.iloc[0, :].fillna("Nan") != df.iloc[8, :].fillna("Nan")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            df = pd.DataFrame(
                np.random.randint(0, 20, (10, 10)).astype(float),
                columns=["c%d" % d for d in range(10)],
            )
            df.where(
                np.random.randint(0, 2, df.shape).astype(bool), np.nan, inplace=True
            )
        return df

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

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

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

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


def g(array):
    row_0 = np.where(np.isnan(array[0, :]), 'Nan', array[0, :])
    row_8 = np.where(np.isnan(array[8, :]), 'Nan', array[8, :])
    return np.array(['c%d' % i for i in range(array.shape[1])])[row_0 == row_8]

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        row_0 = np.where(np.isnan(array[0, :]), 'Nan', array[0, :])
        row_8 = np.where(np.isnan(array[8, :]), 'Nan', array[8, :])
        return np.array(['c%d' % i for i in range(array.shape[1])])[row_0 == row_8]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            array = np.random.randint(0, 20, (10, 10)).astype(float)
            mask = np.random.randint(0, 2, array.shape).astype(bool)
            array[~mask] = np.nan
        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(ans, result)
        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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.columns[df.iloc[0,:].fillna('Nan') == df.iloc[8,:].fillna('Nan')]

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.columns[df.iloc[0, :].fillna("Nan") == df.iloc[8, :].fillna("Nan")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            df = pd.DataFrame(
                np.random.randint(0, 20, (10, 10)).astype(float),
                columns=["c%d" % d for d in range(10)],
            )
            df.where(
                np.random.randint(0, 2, df.shape).astype(bool), np.nan, inplace=True
            )
        return df

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

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

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

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


def g(array):
    row0 = np.where(np.isnan(array[0]), 'Nan', array[0])
    row8 = np.where(np.isnan(array[8]), 'Nan', array[8])
    return [f'c{i}' for i in range(array.shape[1]) if row0[i] != row8[i]]

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        row0 = np.where(np.isnan(array[0]), 'Nan', array[0])
        row8 = np.where(np.isnan(array[8]), 'Nan', array[8])
        return [f'c{i}' for i in range(array.shape[1]) if row0[i] != row8[i]]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            array = np.random.randint(0, 20, (10, 10)).astype(float)
            mask = np.random.randint(0, 2, array.shape).astype(bool)
            array[~mask] = np.nan
        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:
        assert 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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return (df.columns[df.iloc[0,:].fillna('Nan') != df.iloc[8,:].fillna('Nan')]).values.tolist()

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.columns[df.iloc[0, :].fillna("Nan") != df.iloc[8, :].fillna("Nan")]
        ).values.tolist()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            df = pd.DataFrame(
                np.random.randint(0, 20, (10, 10)).astype(float),
                columns=["c%d" % d for d in range(10)],
            )
            df.where(
                np.random.randint(0, 2, df.shape).astype(bool), np.nan, inplace=True
            )
        return df

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

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

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

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(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(array):
    row0 = np.nan_to_num(array[0], nan=np.inf)
    row8 = np.nan_to_num(array[8], nan=np.inf)
    diff_indices = np.where(row0 != row8)[0]
    result = [(array[0, i], array[8, i]) for i in diff_indices]
    return result

result = g(array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        array = data
        row0 = np.nan_to_num(array[0], nan=np.inf)
        row8 = np.nan_to_num(array[8], nan=np.inf)
        diff_indices = np.where(row0 != row8)[0]
        result = [(array[0, i], array[8, i]) for i in diff_indices]
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            array = np.random.randint(0, 20, (10, 10)).astype(float)
            mask = np.random.randint(0, 2, array.shape).astype(bool)
            array[~mask] = np.nan
        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:
        assert len(result) == len(ans)
        for i in range(len(result)):
            for j in range(len(result[i])):
                if np.isnan(result[i][j]) or np.isnan(ans[i][j]):
                    assert np.isnan(result[i][j]) and np.isnan(ans[i][j])
                else:
                    assert result[i][j] == ans[i][j]
        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(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    cols = (df.columns[df.iloc[0,:].fillna('Nan') != df.iloc[8,:].fillna('Nan')]).values
    result = []
    for col in cols:
        result.append((df.loc[0, col], df.loc[8, col]))
    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
        cols = (
            df.columns[df.iloc[0, :].fillna("Nan") != df.iloc[8, :].fillna("Nan")]
        ).values
        result = []
        for col in cols:
            result.append((df.loc[0, col], df.loc[8, col]))
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(10)
            df = pd.DataFrame(
                np.random.randint(0, 20, (10, 10)).astype(float),
                columns=["c%d" % d for d in range(10)],
            )
            df.where(
                np.random.randint(0, 2, df.shape).astype(bool), np.nan, inplace=True
            )
        return df

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

def exec_test(result, ans):
    try:
        assert len(result) == len(ans)
        for i in range(len(result)):
            for j in range(len(result[i])):
                if np.isnan(result[i][j]) or np.isnan(ans[i][j]):
                    assert np.isnan(result[i][j]) and np.isnan(ans[i][j])
                else:
                    assert result[i][j] == ans[i][j]
        return 1
    except:
        return 0

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

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


import numpy as np

arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]])

arr = ... # put solution in this variable

def g(arr):
    return arr.flatten()

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return arr.flatten()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(
                [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]
            )
        if test_case_id == 2:
            arr = np.array(
                [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
            )
        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(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

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

import pandas as pd
import numpy as np

df = pd.DataFrame([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]],columns=['A','B','C','D','E'])

df = ... # put solution in this variable

def g(df):
    df_out = df.stack()
    df_out.index = df_out.index.map('{0[1]}_{0[0]}'.format)
    return df_out.to_frame().T

df = g(df.copy())

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

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df_out = df.stack()
        df_out.index = df_out.index.map("{0[1]}_{0[0]}".format)
        return df_out.to_frame().T

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],
                columns=["A", "B", "C", "D", "E"],
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], columns=["A", "B", "C", "D", "E"]
            )
        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 test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "for" not in tokens and "while" not in tokens