Add Row to pandas DataFrame in Python (2 Examples) | Append List | How to Insert New Line in Middle

Add Row to pandas DataFrame in Python (2 Examples) | Append List | How to Insert New Line in Middle

How to append a new row to a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/add-row-t... Python code of this video: import pandas as pd # Import pandas library to Python data = pd.DataFrame({'x1':range(8, 3, - 1), # Create example DataFrame 'x2':[2, 7, 5, 1, 3], 'x3':range(11, 16)}) print(data) # Print example DataFrame new_row = [1, 2, 3] # Create new row print(new_row) # Print new row [1, 2, 3] data_new1 = data.copy() # Create copy of DataFrame data_new1.loc[5] = new_row # Append new row print(data_new1) # Print updated DataFrame data_new2 = data.copy() # Create copy of DataFrame data_new2.loc[2.5] = new_row # Insert new row data_new2 = data_new2.sort_index().reset_index(drop = True) # Reset index print(data_new2) # Print updated DataFrame Follow me on Social Media: Facebook – Statistics Globe Page:   / statisticsglobecom   Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe   Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython   LinkedIn – Statistics Globe Page:   / statisticsglobe   LinkedIn – R Programming Group for Discussions & Questions:   / 12555223   LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534   Twitter:   / joachimschork   Music by bensound.com