How To Do A Fifo Push-operation For Rows On Pandas Dataframe In Python?
I need to maintain a Pandas dataframe with 500 rows, and as the next row becomes available I want to push that new row in and throw out the oldest row from the dataframe. e.g. Let'
Solution 1:
@JohnGalt posted an answer to this on the comments. Thanks a lot. I just wanted to put the answer here just in case if people are looking for similar information in the future.
df.shift(1)
df.loc[0] = new_row
df.shift(n) will shift the rows n times, filling the first n rows with 'na' and getting rid of last n rows. The number of rows of df will not change with df.shift.
I hope this is helpful.
Post a Comment for "How To Do A Fifo Push-operation For Rows On Pandas Dataframe In Python?"