我需要一个等效于下面的SQL连接的熊猫,现在这会减慢速度...
# SQL lite solution
import sqlite3
#Make the db in memory
conn = sqlite3.connect(':memory:')
#write the tables
df_weather.to_sql('weather', conn, index=False)
data.to_sql('flights', conn, index=False)
qry = '''
select *
from weather left join flights
ON weather.AIRPORT_IATA = flights.destination
AND flights.scheduled_arrival_time BETWEEN weather.VALID_FROM_TIME AND weather.VALID_TO_TIME
'''
data = pd.read_sql_query(qry, conn)
是否有一种熊猫方法将两个df与上述SQL合并? (在之间使用)
scheduled_arrival_time
,VALID_FROM_TIME
和VALID_TO_TIME
是时间戳记。
简单的熊猫合并将不起作用。