Skip to content
Advertisement

replicating data in same dataFrame

I want to replicate the data from the same dataframe when a certain condition is fulfilled. Dataframe:

JavaScript

I want to replicate the dataframe when going through a loop and there is a difference greater than 4 in row.hour.

Expected Output:

JavaScript

i want to replicate the rows when the iterating through all the row and there is a difference greater than 4 in row.hour row.hour[0] = 1 row.hour[1] = 2.here the difference between is 1 but in (row.hour[2]=4 and row,hour[3]=10).here the difference is 6 which is greater than 4.I want to replicate the data above of the index where this condition(greater than 4) is fulfilled I can replicate the data with **df = pd.concat([df]*2, ignore_index=False)**.but it does not replicate when i run it with if statement

I tried the code below but nothing is happening.

JavaScript

Advertisement

Answer

My understanding is: you want to compare ‘Hour’ values for two successive rows. If the difference is > 4 you want to add the previous row to the DF. If that is what you want try this:

Create a DF:

JavaScript

Define a function:

JavaScript

Call the function passing your DF:

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