我正在尝试使用 Traffic library
下载一个大对象并将其存储在一个 csv 文件中from traffic.data import opensky, airports
low_memory=False
airport = airports['LEMD']
flight = opensky.history(start="2021-06-01 00:00",stop="2021-06-16 00:00",arrival_airport=airport.icao)
flight.to_csv(r"C:\Users\peter\Desktop\cosicas.csv")
但是在它开始运行后不久,就出现了:
DtypeWarning: Columns (18) have mixed types.Specify dtype option on import or set low_memory=False.
flight = opensky.history(start="2021-05-15 00:00",stop="2021-06-16 00:00",arrival_airport=airport.icao)
最后:
MemoryError: Unable to allocate 2.54 GiB for an array with shape (7, 48728454) and data type float64
我读了很多书,this answer 似乎是最好的解决方案,但我不知道如何在下载之前 分配 dtype (?)。
答案 0 :(得分:0)
正如 Nick ODell 所评论的那样,最好进行较小的搜索,甚至是像这样的小搜索循环:
from traffic.data import opensky, airports
import pickle, pandas
airport = airports['LEMD']
fechas = pandas.date_range(start="2021-05-30",end="2021-06-14")
VUELO = opensky.history(start=fechas[0],stop=fechas[1],arrival_airport=airport.icao)
for x in range(1,len(fechas)-1):
vuelo = opensky.history(start=fechas[x],stop=fechas[x+1],arrival_airport=airport.icao)
VUELO = vuelo + VUELO
del vuelo
file_to_store = open(r"C:\Users\Shadow\Desktop\stored_object2.pickle", "wb")
pickle.dump(VUELO, file_to_store)
file_to_store.close()
泡菜是为了以后使用下载对象生成牛郎神图。