I have a data frame (below is only the subset):
Data1 | Data2 | Status |
---|---|---|
1 | False | |
2 | True | |
5 | True |
I would like to put a value(string) in column Data2 = "Done" if the Status = True (boolean).
My code is:
d = {"Data1":[1,2,5], "Data2":["","",""], "Status": [False, True, True]}
df = pd.DataFrame(data = d)
for x in range(len(df["Status"])):
if df["Status"].loc[x] == True:
df["Data2"].loc[x] = "Done"
else:
df["Data2"].loc[x] = ""
This code works. My question is: is there any way to do it without loop?