Ramakrishna Nimmathota
Ramakrishna Nimmathota

Reputation: 561

Create duplicate column in pandas dataframe

I want to duplicate a column which has numerical character in the start position. ie(1stfloor)

In simple term, I want to convert column 1stfloor to FirstFloor

df
    1stfloor
    456 
    784
    746
    44 
    9984

Tried using the below code,

df['FirstFloor'] = df['1stfloor']

encountered with below error message:

A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

Expected output:

df

FirstFloor 
456 
784
746
44 
9984

Upvotes: 12

Views: 53163

Answers (1)

Ramakrishna Nimmathota
Ramakrishna Nimmathota

Reputation: 561

df['FirstFloor'] = df['1stfloor'] 
df['FirstFloor'] = df.loc[:, '1stfloor']

Both worked!

Upvotes: 28

Related Questions