pandas dataframe insert column code example
Example 1: pandas insert column in the beginning
insert_index = 0
insert_colname = 'new column'
insert_values = [1, 2, 3, 4, 5]
df.insert(loc=insert_index, column=insert_colname, value=insert_values)
Example 2: how to add a column to a pandas df
df.insert(location, column_name, list_of_values)
df.insert(0, 'new_column', ['a','b','c'])
df['new_column_name'] = value
Example 3: how to add the column to the beginning of dataframe
df.insert(2, 'new-col', data)