0

I have a df:

 A B C D 0 a f k p 1 b g l r 2 c h m s 3 d i n t 4 e j o u 

And I want to update column B with a column

B a b c 

But at position n, meaning I will keep n-1 rows and update the rest.

So the output would be for updating at index 2:

 A B C D 0 a f k p 1 b a l r 2 c b m s 3 d c n t 4 e j o u 

How would one do this?

1
  • can you provide your two inputs as python objects? Commented Mar 21, 2022 at 13:27

1 Answer 1

1

IIUC, and assuming the first input is a dataframe df second input is a Series s:

n = 1 # second row (python indexes from 0) df.update(s.set_axis(range(n, len(s)+n))) 

output:

 A B C D 0 a f k p 1 b a l r 2 c b m s 3 d c n t 4 e j o u 

input df:

 A B C D 0 a f k p 1 b g l r 2 c h m s 3 d i n t 4 e j o u 

input s:

0 a 1 b 2 c Name: B, dtype: object 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.