提前感谢您的帮助
我试图从时间序列数据创建一个热图,该数据从年中开始,这导致热图的顶部向左移动,与图的其余部分不匹配(如下所示)。我该如何移动顶部的线条,以便数据的可视化与绘图的其余部分同步
(代码如下所示)
import pandas as pd
import matplotlib.pyplot as plt
# links to datadata
url1 = 'https://raw.githubusercontent.com/the-datadudes/deepSoilTemperature/master/minotDailyAirTemp.csv'
# load the data into a DataFrame, not a Series
# parse the dates, and set them as the index
df1 = pd.read_csv(url1, parse_dates=['Date'], index_col=['Date'])
# groupby year and aggregate Temp into a list
dfg1 = df1.groupby(df1.index.year).agg({'Temp': list})
# create a wide format dataframe with all the temp data expanded
df1_wide = pd.DataFrame(dfg1.Temp.tolist(), index=dfg1.index)
# ploting the data
fig, (ax1) = plt.subplots(ncols=1, figsize=(20, 5))
ax1.matshow(df1_wide, interpolation=None, aspect='auto');
现在,问题是什么,数据集上的日期,如果您看到数据集是从这个开始的
为了解决这个问题,有必要添加1990/01/01-/04/23之间的数据,并删除2月29日的数据
用这些数据
未填充部分的问题是数据集上NaN值的结果,在这种情况下,您可以选择将NaN值替换为列平均值或替换为行平均值。 可以使用其他方法替换NaN值
相关问题 更多 >
编程相关推荐