2017-02-16 90 views

回答

1

使用+

df.col_2 = df.col_2 + 'new' 
print (df) 
    col_1 col_2 
0  1 anew 
1  2 bnew 
2  3 cnew 
3  4 dnew 
4  5 enew 

感謝hooy另一種解決方案:

df.col_2 += 'new' 

或者assign

df = df.assign(col_2 = df.col_2 + 'new') 
print (df) 
    col_1 col_2 
0  1 anew 
1  2 bnew 
2  3 cnew 
3  4 dnew 
4  5 enew 
+1

或甚至與'df.col_2 + =「new''短。 – hooy

+1

@hooy - 謝謝。 – jezrael

+0

@jezrael它說,df沒有要分配的屬性,並且使用+也不起作用。有沒有辦法通過循環做到這一點?即:'對於我在df ['col2']: .... i +'new'' –

相關問題