我認爲你需要把它分配給新的列:
flight_data_finalcopy['new'] = flight_data_finalcopy["DepDelay"] +
flight_data_finalcopy["ArrDelay"]
或者使用add
:通過評論
flight_data_finalcopy['new'] = flight_data_finalcopy["DepDelay"].add(
flight_data_finalcopy["ArrDelay"])
編輯:
刪除sum_arrival_delay = flight_data_finalcopy["sumDepArr"]
然後更換sum_arrival_delay
到flight_data_finalcopy
:
樣品:
flight_data_finalcopy = pd.DataFrame({'DepDelay':[1,2,3],
'ArrDelay':[4,5,6],
'UniqueCarrier':[7,8,9],
'AirlineID':[1,3,5],
'Another_column':[4,8,9]})
print (flight_data_finalcopy)
AirlineID Another_column ArrDelay DepDelay UniqueCarrier
0 1 4 4 1 7
1 3 8 5 2 8
2 5 9 6 3 9
flight_data_finalcopy["sumDepArr"] = flight_data_finalcopy["DepDelay"] + flight_data_finalcopy["ArrDelay"]
sum_arrival_delay_filter = flight_data_finalcopy[["UniqueCarrier", "AirlineID", "DepDelay", "ArrDelay", "sumDepArr"]]
print (sum_arrival_delay_filter)
UniqueCarrier AirlineID DepDelay ArrDelay sumDepArr
0 7 1 1 4 5
1 8 3 2 5 7
2 9 5 3 6 9
也許我之前並不清楚我想要的東西。我更新了上面的代碼!請再次感謝@jezrael –
請檢查更新 – jezrael
它是如何工作的? – jezrael