Hi how’s it going? Here is an example of the dataframe, and a new data row to be added.
df = DataFrame(:name=>["john","john","john","john","john","mike","mike","mike","mike","mike"]
,:day=>["2020-05-14","2020-05-13","2020-05-12","2020-05-11","2020-05-10","2020-05-14","2020-05-13","2020-05-12","2020-05-11","2020-05-10"],
:earnings=>[20,15,17,32,15,87,65,80,56,90])
df[:day] = DateTime.(df[:day])
new_data = DataFrame(:name=>["john"],:day=>["2020-05-15"],:earnings=>[18])
new_data[:day] = DateTime.(new_data[:day])
heres a screenshot for a better view of the data:
In this case, I would like to maintain the 5 most recent data entries per “name”. So the new_data row should be added to df, and the oldest row for “john” which was on “2020-05-10” should be popped off the back end.
What is the best and most efficient way to implement this?