我正在尝试使用pandas将一行表转换为12列150年的表。基本上,一年过去了,Y轴和月份在X轴上。你知道吗
我的df返回以下信息:
如何使用第一列中的日期创建x轴上有年份,y轴上有12个月的表?你知道吗
for county in CntyList:
for model in models:
for num in range(0, 33):
#Outfile = r'E:\\ClimateChange\\Tables\\Counties\\' + str(county) + r'_' + str(folder) + r'_' + str(model) + r'.csv'
rows = concatDF.ix[num]
print(rows)
我不太清楚我们在问什么,因为它的重要是张贴一个原始数据(不是一个图像)以及您正在寻找的输出样本最小的例子。你知道吗
尽管如此,我还是尝试先为您重新创建一些假数据,然后以您所描述的方式对其进行透视。你知道吗
首先创建假数据
我假设你有1800行原始数据-从1950年开始的150年中,每行1个月。你知道吗
原始数据输出
这是数据帧的头部-1950年的前5个月
还有尾巴——2099年的最后5个月
从索引创建日期时间
现在我们可以使用
to_datetime
函数将索引转换为时间戳将年和月转换为数据帧列
最后,对数据进行透视,得到一个包含150行和12列的表
有输出
供您实施
使用
to_datetime
将索引转换为日期时间。将列year
和month
添加到数据帧中,然后对其进行透视。如果这是你想要的,请在评论中告诉我。你知道吗相关问题 更多 >
编程相关推荐