熊猫在两个日期之间加入数据

时间:2019-10-08 11:36:44

标签: python sql pandas

我需要一个等效于下面的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_timeVALID_FROM_TIMEVALID_TO_TIME是时间戳记。

简单的熊猫合并将不起作用。

0 个答案:

没有答案