Hi,
I have dataframe, I wan to define new column same as Column1, and re-arrange the new columns rows as:
new_col rows 0-end should be replaced with first column row1-end
TypeError: unhashable type: 'slice'
my desired output:
I use this way, and it works:
df['new_col']=df['new_col'].shift(-1)
I have dataframe, I wan to define new column same as Column1, and re-arrange the new columns rows as:
new_col rows 0-end should be replaced with first column row1-end
1 2 3 4 5 6 |
import pandas as pd df = pd.DataFrame({ 'Col1' : [ 1 , 2 , 3 , 4 , 5 ], 'Col2' : [ 6 , 7 , 8 , 9 , 10 ], 'Col3' : [ 11 , 12 , 13 , 14 , 15 ]}) df[ 'new_col' ] = df[ 'Col1' ] df[ 0 : - 1 , 'new_col' ] = df.ix[ 1 :, 'Col1' ] |
my desired output:
1 2 3 4 5 6 |
Col1 Col2 Col3 new_col 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 5 |
I use this way, and it works:
df['new_col']=df['new_col'].shift(-1)