Pandas assignment an boolean alignment logic

1 week ago 12
ARTICLE AD BOX

Here are some pandas questions that have been driving me nuts (I have OCD about this).

1.Do these assignments always align by index label and column position?

#Problem 1a df[col1] = seriesObject #Problem 1b df[[col1,col2]] = df2[[col1,col2]]

2.Do these assignments always align by index label and column label?

#Probelm 2a df.loc[:,col1] = df2[col1] #Problem 2b df.loc[:,[col1,col2]] = df2[[col2,col1]]

3.Do we have the same alignment by index and column label when using a boolean mask?

#Probelm 3a df.loc[mask,col1] = df2[col1] #Problem 3b df.loc[mask,[col1,col2]] = df2[[col2,col1]]

4. Lastly, if all of these align by row index rather than position, what happens with duplicate indices?

Thanks for all of the help!

Read Entire Article