Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

KeyError: "None of [Index([(84, 90, 50, 29, 49, 44, 30, 98, 31, 66), (68, 78, 28, 80, 45, 56, 53, 93, 31, 66)], dtype='object')] are in the [columns]"

I know almost nothing about this stuff. But still, my teacher says she can’t help. I have tried looking at this error, but everything is over my head. What am I doing wrong?

import pandas as pd


data = {"student": ["Anayo","Brandon","Claudia","Dave","Evelyn","Finn","Gloria","Hank","Isla", "Julia" ],
        "test_one": [84, 90, 50, 29, 49, 44, 30, 98, 31, 66],
        "test_two": [68, 78, 28, 80, 45, 56, 53, 93, 31, 66],
        "test_three": [42, 35, 30, 40, 28, 85, 80, 99, 38, 48]
    }


test_data = pd.DataFrame(data)

def max_two(one, two):
    return test_data[[one, two]].max(axis=1)

test_data["max_1_and_2"] = max_two(test_data["test_one"], test_data["test_two"])

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The problem is that your function expects you the column names, but you are sending the actual columns instead. Use:

import pandas as pd

data = {"student": ["Anayo","Brandon","Claudia","Dave","Evelyn","Finn","Gloria","Hank","Isla", "Julia" ],
        "test_one": [84, 90, 50, 29, 49, 44, 30, 98, 31, 66],
        "test_two": [68, 78, 28, 80, 45, 56, 53, 93, 31, 66],
        "test_three": [42, 35, 30, 40, 28, 85, 80, 99, 38, 48]
    }


test_data = pd.DataFrame(data)

def max_two(one, two):
    return test_data[[one, two]].max(axis=1)

test_data["max_1_and_2"] = max_two("test_one", "test_two")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading