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 :
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")