If this is a frequent operation, then it makes sense (in terms of performance) to first collect the data into a list, and then use pd.concat([], ignore_index=True) (similar to @ Serenity Solution ):
Demo:
data = [] # always inserting new rows at the first position - last row will be always on top data.insert(0, {'name': 'dean', 'age': 45, 'sex': 'male'}) data.insert(0, {'name': 'joe', 'age': 33, 'sex': 'male'}) #... pd.concat([pd.DataFrame(data), df], ignore_index=True) In [56]: pd.concat([pd.DataFrame(data), df], ignore_index=True) Out[56]: age name sex 0 33 joe male 1 45 dean male 2 30 jon male 3 25 sam male 4 18 jane female 5 26 bob male
PS I would not call .append() , pd.concat() , .sort_index() too often (for each individual line), since it is quite expensive. So the idea is to do it in pieces ...
source share