Update the column for each row in dataframe

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

def excelsqrtfile(k):
f1=pd.DataFrame(k[‘values’])
if ‘com.infa.ldm.profiling.lastProfileTime’ in f1.attributeId.values:
t=‘Y’
else:
print(“NO”)
t=‘N’
return t

for x in get_list:
df[“sqr”]=excelsqrtfile(x)

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] = ... 

or

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

Thanks!

© Copyright 2013-2021 Analytics Vidhya