10

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
sophocles
  • 13,593
  • 3
  • 14
  • 33
  • 2
    Possible duplicate of [Confusion re: pandas copy of slice of dataframe warning](https://stackoverflow.com/questions/38835483/confusion-re-pandas-copy-of-slice-of-dataframe-warning) – Yuca Aug 15 '19 at 18:46

1 Answers1

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

Both worked!

Charles
  • 104
  • 12