Update the column for each row in dataframe

I am trying to update the value of a column in df[“sqr”]

def excelsqrtfile(k):
if ‘com.infa.ldm.profiling.lastProfileTime’ in f1.attributeId.values:
return t

for x in get_list:

for the first row, it returns - N and for the second row it returns the value - Y

But in the df[“sqr”] the values are showing as ‘Y’ for two rows. even though I could print the values as No and Yes in python.

Can you advise me where I am doing wrong?

My expectation is - for the first row of df[“sqr”] = N and for the second row df[“sqr”]= Y.

Many thanks in advance.

First: edit question and use special button to format code. Code without indentations is useless.

Second: put example data in code - so we could run it - and show expected result. And you should also explain what is get_list.

Third: df["sqr"] = ... means to assing value to all rows - not to single row.

You should use something like this (without for-loop)

df["sqr"] = df.apply(excelsqrtfile)

(but I don’t know what is x and get_list)

Or you should work with every row separatelly using iloc like

df["sqr"].iloc[0] = ... 
df["sqr"].iloc[1] = ... 


df["sqr"][0] = ... 
df["sqr"][1] = ... 


© Copyright 2013-2021 Analytics Vidhya