read through 4 csv files in python and printing out the row based from the column id -
Hi guys, I'm a Noah in Python and I am currently learning, and I was thinking that someone could help me with the problem. Facing up I have four files: routes.txt, trips.txt, stop_times.txt, stops.txt, files look like this (files have thousands of rows):
routes.txt "route_id", "Agency_id", "route_short_name", "route_long_name", "route_desc", "route_type", "route_url", "route_color", "route_text_color" "01", "1", "1", 3, "fff 7 "," 000000 "" 04 "," 1 "," 4 ", 3," FFFF 7C "," 000000 "" 05 "," 1 "," 5 ", 3," FFFF7C " "Direction_id", "trip_headsign", "trip_headsign", "trap_headsense", "trailer", "000000" "7", "1", "7", 3, "FFFF7C", "000000" trips.txt "route_id", "service_id" , "Block_id", "shape_id" "108", "BUSN13-hbf13011- working day -02", "19,417,636", "Malden Station Salem St By Medford Square "," Medford Square ", 0," West Medford ", 1," F411-75 "," 1,080,037 "" 94 "," BUSN13-hbf13011- Working Days -02 "," 19,417,637 " F94-5 "," 940014 "," trip_id "," 14:40:00 "," 14:40:00 "," 7412 ", 1, 0,0" 19417636 "," 14:41:00 "," 14:41:00 "," 6283 " , 2, 0,0 "19417636", "14:41:00", "14:41:00", "6284", 3, 0,0 stops .txt stop_id "," stop_code "," "", "Stop_desc", "stop_lat", "stop_lon", "zone_id", "stop_url", "LOCATION_TYPE", "parent_station", "space-alfcl" "" elewf station "," 42.395428 "," - 71.142483 " , "", "", 1, "" location-algeg "," "," olus Tone St. Station "," "," 42.348701 "," -71.137 9 55 "," "," ", 1," "space-Andrew", "", "Andrew Station", "", "42.330154" "- 71.057655", "", "", 1, "" I am trying to print the rows based on the column id. For example if we have route_ID = "01" is
In routes Check the ID file and check whether the trip_id is in the trips.txt file via ID id. If the match is equal
move trip_id from the trips.txt file and compare it to trip_id in the trip_times.txt file If it is a match check, then
stop_id stop_file. Txt file is equal to stop_id, then print it. Now the stop_id can be a number or string What I am trying to print is to print something like this, for example:
route_id, trip_id, arrival_time, departure_time, stop_name 01,19417636, 14: 40: 00, 14: 40: 00, alveef station very approved
What are you trying to do that are called A, and can be done very easily by using the library: / P>
import pd routes as pd = pd.read_csv ('routes.txt') trips = pd.read_csv ('trips.txt') stop_times = pd.read_csv ('stop_times.txt') stops = pd .read_csv ('stops.txt') You may have to change it so that it can properly interpret your data (especially on route_id s Zero) # Please excuse the name of the Dr. Seas variable routes_trips = pd.merge (routes, trips, at ['route_id']) routes_trips_stop_times = pd.merge (routes_trips, stop_times, = at [ 'Trip_id']) routes_trips_stop_times_names = PD By default, the pandals are found by default, so you will end up with the rows where the match route_id / Code> s, trip_id s and stop_id s.
Comments
Post a Comment