I have a dataframe that has rows with indices 0 to 128 and a smaller dataframe with indices 4, 8, 105, and 107.

I made edits to the rows in the smaller dataframe and am now trying to replace rows indexed 4, 8, 105, and 107 in the large dataframe with rows indexed 4, 8, 105, and 107 in the smaller dataframe.

Why can I not just do:

bigDF[smallDF.index] = smallDF

How would I accomplish this replacement? Thank you!


1 Answer 1


In your code, you passed smallDF.index directly. The interpreter considers this as a list of column names. So your code will be interpreted like below. But 4,8,105,107 are not columns. They are indexes.

bigDF[[4,8,105,107] = smallDF

To locate a row based on the index, use the loc function. Try using below.


  • $\begingroup$ It would be better if you could add an explaination to your answer $\endgroup$
    – Jonathan
    Jul 29, 2021 at 12:04
  • 1
    $\begingroup$ @Sammy Updated my comment. Thanks. $\endgroup$
    – Venkat
    Jul 29, 2021 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.