0

Suppose I have a slice of a column within a dataframe df where I want to replace float values with other float values. Only the values to replace are from another dataframe, `newdf.

I've tried using

df.loc[row index condition, [column to replace vals]] = newdf[column]

but for some reason the resulting values are all NaN. Why is this so?

1 Answer 1

2

The value from newdf need to align with the index of df. If newdf has the exact number of values you want to insert, you can try using .values:

df.loc[row index condition, [column to replace vals]] = newdf[column].values
Sign up to request clarification or add additional context in comments.

1 Comment

.values was the trick! The slice is the exact same number of rows, but I could no longer merge on indices. Perfect, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.