Как мне найти прямые рейсы, один маршрут пересадки и два маршрута пересадки из определенного пункта назначения? ИспользоPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как мне найти прямые рейсы, один маршрут пересадки и два маршрута пересадки из определенного пункта назначения? Использо

Сообщение Anonymous »

У меня есть файл с именем маршруты из https://openflights.org/data.php со следующими столбцами:
Airline 2-letter (IATA) or 3-letter (ICAO) code of the airline.
Airline ID Unique OpenFlights identifier for airline (see Airline).
Source airport 3-letter (IATA) or 4-letter (ICAO) code of the source airport.
Source airport ID Unique OpenFlights identifier for source airport (see Airport)
Destination airport 3-letter (IATA) or 4-letter (ICAO) code of the destination airport.
Destination airport ID Unique OpenFlights identifier for destination airport (see Airport)
Codeshare "Y" if this flight is a codeshare (that is, not operated by Airline, but another carrier), empty otherwise.
Stops Number of stops on this flight ("0" for direct)
Equipment 3-letter codes for plane type(s) generally used on this flight, separated by spaces

.
Во-первых, я хочу найти те маршруты, которые получены из пунктов назначения моих прямых рейсов из определенного аэропорта (например, LEX). . Затем сделайте то же самое для двух маршрутов передачи.
Я использовал pandas для создания фреймов данных из CSV.
# Get the list of all destination airports from LEX
lex_destinations = lex_routes['dest'].unique()

# Select routes from those destination airports
one_transfer_routes = routes[routes['source'].isin(lex_destinations)]

# Remove routes that come back to LEX (or revisit any airport twice)
one_transfer_routes = one_transfer_routes[~one_transfer_routes['dest'].isin(['LEX'])]

#Join with the airports to have the lat, lon to plot them using folium
one_transfer_routes_1 = pd.merge(one_transfer_routes, airports,
left_on='dest_id',
right_on='id',
how='left',
suffixes=['_source','_dest'])

# Get the list of all destinations from LEX's first connections
first_transfer_destinations = one_transfer_routes['dest'].unique()

# Get routes from those destinations to find second transfer connections
two_transfer_routes = routes[routes['source'].isin(first_transfer_destinations)]

# Again, filter out any routes that come back to LEX or revisit any airport twice
two_transfer_routes = two_transfer_routes[~two_transfer_routes['dest'].isin(['LEX'])]

two_transfer_routes = pd.merge(two_transfer_routes, airports,
left_on='dest_id',
right_on='id',
how='left',
suffixes=['_source','_dest'])


Подробнее здесь: https://stackoverflow.com/questions/790 ... he-two-tra
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»