python - Adding two columns in a dataframe and displaying other columns -
hello added 2 columns , got column display sum of 2 columns successfully. want display other columns along summed column. example show arrdelay
, depdelay
or column if choose along summed column.
here code below:
flight_data_finalcopy["sumdeparr"] = flight_data_finalcopy["depdelay"] + flight_data_finalcopy["arrdelay"] sum_arrival_delay = flight_data_finalcopy["sumdeparr"] sum_arrival_delay_fliter = sum_arrival_delay[["uniquecarrier", "airlineid", "depdelay", "arrdelay", "sumdeparr"]] print(display(sum_arrival_delay_filter))
i think need assign new column:
flight_data_finalcopy['new'] = flight_data_finalcopy["depdelay"] + flight_data_finalcopy["arrdelay"]
or use add
:
flight_data_finalcopy['new'] = flight_data_finalcopy["depdelay"].add( flight_data_finalcopy["arrdelay"])
edit comment:
remove sum_arrival_delay = flight_data_finalcopy["sumdeparr"]
, replace sum_arrival_delay
flight_data_finalcopy
:
sample:
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
Comments
Post a Comment