Skip to content
Advertisement

Concat following row to the right of a df – python

I’m aiming to subset a pandas df using a condition and append those rows to the right of a df. For example, where Num2 is equal to 1, I want to take the following row and append it to the right of the df. The following appends every row, where as I just want to append the following row after a 1 in Num2. I’d also like to be able to append specific cols. Using below, this could be only Num1 and Num2.

JavaScript

intended output:

JavaScript

Advertisement

Answer

You can try:

JavaScript

OR

JavaScript

If needed use fillna():

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement