Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create duplicate column in pandas dataframe

Tags:

python-3.x

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
like image 239
Ramakrishna Nimmathota Avatar asked Mar 04 '23 14:03

Ramakrishna Nimmathota


1 Answers

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

Both worked!

like image 128
Ramakrishna Nimmathota Avatar answered Apr 10 '23 13:04

Ramakrishna Nimmathota