pandas - Print Column contents, according to particular contents of another column -
i have dataframe columns trip_id, service_id etc., like
trip_id service_id 1 weekday 2 weekday 3 weekday 4 saturday 5 saturday 6 holiday 7 sunday
i want print out trip_id's 'weekday', saturdays , holidays, separately. tried
join_df.query(join_df['service_id'] == 'weekday')
way, doesn't seem right one. tried
print join_df[join_df.service_id =='weekdays']
didnt work. got empty dataframe output.
could me please. thank you
this looks typo (it's weekday not weekdays), either latter or using loc should work:
in [11]: df[df.service_id == 'weekday'] out[11]: trip_id service_id 0 1 weekday 1 2 weekday 2 3 weekday in [12]: df.loc[df.service_id == 'weekday'] out[12]: trip_id service_id 0 1 weekday 1 2 weekday 2 3 weekday
you can use query, syntax isn't quite correct:
in [13]: df.query("service_id == 'weekday'") out[13]: trip_id service_id 0 1 weekday 1 2 weekday 2 3 weekday