How to insert a column at a specific index in pandas dataframe?

pandas
python

#1

Hello,

I have a pandas dataframe df in which I want to insert a new column ‘result’ next to column named ‘acceleration’ which has column index=3.

How can we insert the result column at index =4 in the dataframe df?

Thanks


#2

Hello,

We can insert a column in a dataframe df using function
df.insert( index,name,value)
here index = the index where u want to insert the column
name = name of the column
value = data of the column

Here use df.insert( 4,‘result’, result)

Thanx