Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have an existing dataframe which I need to add an additional column to which will contain the same value for every row.

Existing df:

Date, Open, High, Low, Close

01-01-2015, 565, 600, 400, 450

New df:

Name, Date, Open, High, Low, Close

abc, 01-01-2015, 565, 600, 400, 450

I know how to append an existing series / dataframe column. But this is a different situation, because all I need is to add the 'Name' column and set every row to the same value, in this case 'abc'.

Im not entirely sure how to do that.

1 Answer

0 votes
by (41.4k points)

Use this df['Name']='abc'. It will add the new column and set all rows to that value:

In [79]:

df

Out[79]:

         Date, Open, High,  Low,  Close

0  01-01-2015,  565,  600,  400,    450

In [80]:

df['Name'] = 'abc'

df

Out[80]:

         Date, Open, High,  Low,  Close Name

0  01-01-2015,  565,  600,  400,    450  abc

Browse Categories

...