I have a dataframe and want to insert a new column for it. However, I have to insert this column multiple times, each time for some rows. E.g.
source feature 1 feature 2 0 a xxx xxx 1 b xxx xxx 2 c xxx xxx 3 a xxx xxx I want to insert a feature 3. However, for different sources, I have to do it separately.
First, I got the index of df['source'] ==a , and a list of their values E.g.
index_for_a = [0,3] values_for_a = [2, 4] source feature 1 feature 2 feature_3 0 a xxx xxx 2 1 b xxx xxx 2 c xxx xxx 3 a xxx xxx 4 Is there any API I can use to insert the value for multiple specified rows? I found one dataframe.insert(). However, it only works for one specific location so I have to iterate on the rows. Is there any more efficient way to do so?