0
$\begingroup$

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!

$\endgroup$
0
$\begingroup$

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.

bigDF.loc[smallDF.index]=smallDF

$\endgroup$
2
  • $\begingroup$ It would be better if you could add an explaination to your answer $\endgroup$
    – Sammy
    Jul 29 at 12:04
  • 1
    $\begingroup$ @Sammy Updated my comment. Thanks. $\endgroup$
    – Venkat
    Jul 29 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.