I use the following method a lot to append a single row to a dataframe. One thing I really like about it is that it allows you to append a simple dict object. For example:
# Creating an empty dataframe
df = pd.DataFrame(columns=['a', 'b'])
# Appending a row
df = df.append({ 'a': 1, 'b': 2 }, ignore_index=True)
Again, what I like most about this is that the code is very clean and requires very few lines. Now I suppose the recommended alternative is:
# Create the new row as its own dataframe
df_new_row = pd.DataFrame({ 'a': [1], 'b': [2] })
df = pd.concat([df, df_new_row])
So what was one line of code before is now two lines with a throwaway variable and extra cruft where I create the new dataframe. :( Is there a good way to do this that just uses a dict like I have in the past (that is not deprecated)?
df.append
was deprecated because: "Series.append and DataFrame.append [are] making an analogy to list.append, but it's a poor analogy since the behavior isn't (and can't be) in place. The data for the index and values needs to be copied to create the result." – Mnemonics