Syntactical doubt

def divide_data(x_data,fkey,fval):
x_right = pd.DataFrame([],columns=x_data.columns)
x_left = pd.DataFrame([],columns=x_data.columns)

for ix in range(x_data.shape[0]):
    val = x_data[fkey].loc[ix] # fkey => feature
    
    if val > fval:
        x_right = x_right.append(x_data.loc[ix])
    else:
        x_left = x_left.append(x_data.loc[ix])
        
return x_left,x_right

in line 5, why cant we write x_data[ix][fkey] ? is there any other way of representation?

Hey @debjanihome, no actually if you want to do it like that than keep in mind, first always we need to access the column and than the row.

So you could have use, x_data[fkey][ix] but not x_data[ix][fkey]. Or if you want to specify row first, than use
x_data.loc[ix][fkey].

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

1 Like