我有以下的代碼,試圖轉換列V2,並添加一個新列:蟒蛇大熊貓數據框:變換列,並將其追加到尾部
df = pd.read_csv('test1.csv')
for index, row in df.iterrows():
v4 = myFunction.classify(row['v2'])
row['v4'] = v4
row.append(v4)
然而,行row.append(v4)
不起作用。將v4追加到每一行的正確方法是什麼?謝謝!
目前,DF的樣子:
v1 v2 v3 result
0 12 Dog 31 0
1 34 Frog 4 1
2 32 Snake 5 1
3 7 Cat 2 0
,並預期新的DF應該是:
v1 v2 v3 result v4
0 12 Dog 31 0 Mammal
1 34 Eagle 4 1 Bird
2 32 Snake 5 1 Reptile
3 7 Cat 2 0 Mammal
爲什麼不'DF [ 'V4'] = myFunction.classify(DF [ 'V2'] )'? – jeremycg