0

I have an array , a= [5,25,15], and a data frame:

volume price loc
4 20 16
3 50 14
NaN NaN NaN
10 40 13

I want to replace the third row of my df with a.

2 Answers 2

1

Use loc for set values, but need match length of list by length of columns:

df.loc[2] = a

If need specify columns:

df.loc[2, ['volume','price','loc']] = a
Sign up to request clarification or add additional context in comments.

Comments

0

Easy- use loc: new_df = df.loc[idx] Passing an array to loc will select rows where index is in the array.

Comments

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.