I am trying to take data from "Mathscore" and convert the values to numeric values, all in the "Mathscore" section.
strong = 1 Weak = 0
I tried to do this using the function below using a For loop, but I cannot run the code. Am I trying to assign data incorrectly?
Thank!
import pandas as pd
data = {'Id_Student' : [1,2,3,4,5,6,7,8,9,10],'Mathscore' :['Strong','Weak','Weak','Strong','Strong','Weak','Strong','Strong','Weak','Strong']}
df = pd.DataFrame(data)
df
def tran_mathscore():
for i in df.Mathscore:
if i == "Strong":
df.Mathscore[i]= ['1']
elif i == "Weak":
df.Mathscore[i]= ['0']
tran_mathscore()
source
share