I see that dataframes have a .pop method but .append returns a new object (unlike for lists). It can be inefficient to constantly reallocate memory for the dataframe as I am adding rows (also see this answer testing preallocating space in reply to a similar question). But I need to duplicate (then modify) some rows, as I outlined in another question (example repeated below) — is this efficient to do with appending rows to the end of dataframe, or in some other way?
I want to get from this (focus on id 2):
id start end
1 2011-01-01 10:00:00 2011-01-08 16:03:00
2 2011-01-28 03:45:00 2011-02-04 15:22:00
3 2011-03-02 11:04:00 2011-03-05 05:24:00
To this:
id start end month stay
1 2011-01-01 10:00:00 2011-01-08 16:03:00 2011-01 7
2 2011-01-28 03:45:00 2011-01-31 23:59:59 2011-01 4
2 2011-02-01 00:00:00 2011-02-04 15:22:00 2011-02 4
3 2011-03-02 11:04:00 2011-03-05 05:24:00 2011-03 3