I am running a conditional loop to create a new column in my DataFrame (TDF) based on the value of column "alone". If the value is 0, add the string "alone" else add "with family" in the column "alone". I am using the code: I am getting the error:
tdf['alone'].loc[['alone'] >0]= 'with family'
tdf['alone'].loc[['alone'] ==0] = 'alone'
After running the above line, I am getting the following error:
KeyError: 'cannot use a single bool to index into setitem'
I referred this same question, and what I gathered is that I need to have row_indexer
in tdf['alone'].loc[[row_indexer,['alone']] = 'alone'
but I am not sure how to get the values in row_indexer