如何在meteostat的Point(lat=float,lon=float)函数中使用浮点数填充的列? Python
How to use a column filled with floats in the function Point(lat=float,lon=float) of meteostat? Python
我正在尝试使用 Daily(Point(lat,lon), start-date, end-date) 构建数据框,meteostat 库 的一个函数,returns 由 Point(lat,lon) 指示的位置的所有每日天气统计数据使用纬度和经度,从开始日期到结束日期。
问题是 (lat, lon) 参数需要 float 和所以只表示一个位置。我想地址几个位置并收集每个位置的每日气象数据。
import meteostat
from datetime import datetime
from meteostat import Point, Daily
import matplotlib.pyplot as plt
from meteostat import Stations
import pandas as pd
import numpy
data = pd.read_csv(r'C:\Users\leoac\OneDrive\Desktop\Coding\Python apps\Correlation temp-goals in Serie A\seasons 09-19.csv', ";")
date_not_converted = data['Date']
date_being_converted = datetime.strptime(date_not_converted,'%d,%m,%Y') #1bis non può essere una serie...allora provo a cambiare il tipo di dati
date = date_being_converted.strftime('%Y,%m,%d')
#plot = Daily(Point(data['lat'][15],data['lon'][15]),d1,d2).fetch()
data['temp'] = Daily(Point(data['lat'][1],data['lon'][1]),datetime(date),datetime(date)).fetch() #1 sistemare il formato data
print(data['temp']) #2 trovare un modo per inserire i vettori date e lat/lon nel df
data['temp'].plot(y=['tavg'])
plt.show()
print(data)
这是受 this github issue 启发的解决方案。它对不同位置发出并行请求,然后将结果合并到 pandas 数据帧中。
from datetime import datetime
from meteostat import Point, Daily
from multiprocessing import cpu_count
from joblib import Parallel, delayed
import pandas as pd
def get_bulk_data(row):
location = Point(row.lat, row.lon)
data = Daily(location, row.Date, row.Date).fetch()
data["latitude"] = row.lat
data["longitude"] = row.lon
return data
if __name__ == "__main__":
df = pd.read_csv("seasons.csv", sep=";")
df["Date"] = pd.to_datetime(df["Date"], format="%d,%m,%Y")
executor = Parallel(n_jobs=cpu_count(), backend='multiprocessing')
tasks = (
delayed(get_bulk_data)(row)
for _, row in df.iterrows()
)
list_of_locations_data = executor(tasks)
data_full = pd.concat(list_of_locations_data)
print(data_full)
它适用于以下 csv 和日期格式,如果您的格式略有不同,您可以调整代码:
Date;lat;lon
18,02,1997;50.3;-4.7
12,07,1998;41.3;1.5
我正在尝试使用 Daily(Point(lat,lon), start-date, end-date) 构建数据框,meteostat 库 的一个函数,returns 由 Point(lat,lon) 指示的位置的所有每日天气统计数据使用纬度和经度,从开始日期到结束日期。
问题是 (lat, lon) 参数需要 float 和所以只表示一个位置。我想地址几个位置并收集每个位置的每日气象数据。
import meteostat
from datetime import datetime
from meteostat import Point, Daily
import matplotlib.pyplot as plt
from meteostat import Stations
import pandas as pd
import numpy
data = pd.read_csv(r'C:\Users\leoac\OneDrive\Desktop\Coding\Python apps\Correlation temp-goals in Serie A\seasons 09-19.csv', ";")
date_not_converted = data['Date']
date_being_converted = datetime.strptime(date_not_converted,'%d,%m,%Y') #1bis non può essere una serie...allora provo a cambiare il tipo di dati
date = date_being_converted.strftime('%Y,%m,%d')
#plot = Daily(Point(data['lat'][15],data['lon'][15]),d1,d2).fetch()
data['temp'] = Daily(Point(data['lat'][1],data['lon'][1]),datetime(date),datetime(date)).fetch() #1 sistemare il formato data
print(data['temp']) #2 trovare un modo per inserire i vettori date e lat/lon nel df
data['temp'].plot(y=['tavg'])
plt.show()
print(data)
这是受 this github issue 启发的解决方案。它对不同位置发出并行请求,然后将结果合并到 pandas 数据帧中。
from datetime import datetime
from meteostat import Point, Daily
from multiprocessing import cpu_count
from joblib import Parallel, delayed
import pandas as pd
def get_bulk_data(row):
location = Point(row.lat, row.lon)
data = Daily(location, row.Date, row.Date).fetch()
data["latitude"] = row.lat
data["longitude"] = row.lon
return data
if __name__ == "__main__":
df = pd.read_csv("seasons.csv", sep=";")
df["Date"] = pd.to_datetime(df["Date"], format="%d,%m,%Y")
executor = Parallel(n_jobs=cpu_count(), backend='multiprocessing')
tasks = (
delayed(get_bulk_data)(row)
for _, row in df.iterrows()
)
list_of_locations_data = executor(tasks)
data_full = pd.concat(list_of_locations_data)
print(data_full)
它适用于以下 csv 和日期格式,如果您的格式略有不同,您可以调整代码:
Date;lat;lon
18,02,1997;50.3;-4.7
12,07,1998;41.3;1.5