2016-11-03 101 views
-1

我想從此列中提取出「A」(s)。做完這些之後,我希望能夠在同一行中打印與「A」關聯的其他列的其他數據。 然而,我的代碼打印此相反:從Python中的數據框中的列提取數據

outputs: 
UniqueCarrier  NaN 
CancellationCode NaN 
Name: CancellationCode, dtype: object 
None 

列「CancellationCode」看起來像這樣

CancellationCode: 
     NaN 
     A 
     NaN 
     B 
     NaN 

我想它在數據幀格式打印帶有過濾的行和列。 這裏是我下面的代碼: 在先進的感謝

cancellation_reason = (flight_data_finalcopy["CancellationCode"] == "A") cancellation_reasons_filtered = cancellation_reason[["UniqueCarrier", "AirlineID", "Origin"]] print(display(cancellation_reasons_filtered))

回答

1

試試這個

cancellation_reason=flight_data_finalcopy[flight_data_finalcopy["CancellationCode"] == "A"] 
cancellation_reasons_filtered = cancellation_reason[["UniqueCarrier", "AirlineID", "Origin"]] 
print(display(cancellation_reasons_filtered)) 
+0

嘿感謝的人,我看到了我的錯誤,我需要另外一對括號的,我是用括號代替方括號! –

相關問題