Python 使用熊猫和geopandas绘制一年内每个月的数据
我有五个国家1991-2020年的数据 临时国家Python 使用熊猫和geopandas绘制一年内每个月的数据,python,pandas,matplotlib,geopandas,Python,Pandas,Matplotlib,Geopandas,我有五个国家1991-2020年的数据 临时国家 Date Temperature Units Year Month Statistics Country CODE Jan 1991 -26.2 Celsius 1991 Jan Average Canada CAN Feb 1991 -21.0 Celsiu
Date Temperature Units Year Month Statistics Country CODE
Jan 1991 -26.2 Celsius 1991 Jan Average Canada CAN
Feb 1991 -21.0 Celsius 1991 Feb Average Canada CAN
Mar 1991 -18.2 Celsius 1991 Mar Average Canada CAN
Apr 1991 -8.6 Celsius 1991 Apr Average Canada CAN
May 1991 0.8 Celsius 1991 May Average Canada CAN
合并
我想在世界地图上画出1991年每个月的温度值。最后,我将得到12幅图,显示每个国家的温度
我如何仅选择1991年,以及如何放置一个标题,指示每个地块的年份和月份
我这样做:
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import geopandas
location=pd.read_excel('countries.xlsx') #Longitude latitude data
tempcountries = pd.read_excel('Temperature Countries.xlsx')
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.columns=['pop_est', 'continent', 'name', 'CODE', 'gdp_md_est', 'geometry']
for y in tempcountries['Year']:
for i in tempcountries['Month']:
fig, ax = plt.subplots(figsize=(8,6))
world.plot(ax=ax, color='lightgrey')
merge.plot(x="longitude", y="latitude", kind="scatter",
c="Temperature", colormap="coolwarm",
ax=ax)
plt.show()
我得到了多个绘图,但我没有看到地图上的颜色(指示温度)发生变化
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import geopandas
location=pd.read_excel('countries.xlsx') #Longitude latitude data
tempcountries = pd.read_excel('Temperature Countries.xlsx')
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.columns=['pop_est', 'continent', 'name', 'CODE', 'gdp_md_est', 'geometry']
for y in tempcountries['Year']:
for i in tempcountries['Month']:
fig, ax = plt.subplots(figsize=(8,6))
world.plot(ax=ax, color='lightgrey')
merge.plot(x="longitude", y="latitude", kind="scatter",
c="Temperature", colormap="coolwarm",
ax=ax)
plt.show()