0
df = pd.DataFrame(np.arange(15).reshape(5,3), columns = ['a', 'b', 'c'])
df

Output:

    a   b   c
0   0   1   2
1   3   4   5
2   6   7   8
3   9  10  11
4  12  13  14

Now, I want to add a new column 'new' to df as below:

df
    a  new   b   c
0   0   11   1   2
1   3   12   4   5
2   6   13   7   8
3   9   14  10  11
4  12   15  13  14

How this can be achieved using pandas?

anky
  • 74,114
  • 11
  • 41
  • 70
ArijitC91
  • 33
  • 4
  • By using insert : `df.insert(1,'new',range(11,16))` ; `print(df)` : Note don't assign this back as it is an inplace operation – anky Jan 17 '20 at 14:53
  • https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.insert.html – Khalil Al Hooti Jan 17 '20 at 14:53

0 Answers0