【发布时间】:2018-11-21 23:23:40
【问题描述】:
我的数据看起来像:
Year Month Region Value1 Value2
2016 1 west 2 3
2016 1 east 4 5
2016 1 north 5 3
2016 2 west 6 4
2016 2 east 7 3
.
.
2016 12 west 2 3
2016 12 east 3 7
2016 12 north 6 8
2017 1 west 2 3
.
.
2018 7 west 1 1
2018 7 east 9 9
2018 7 north 5 1
我想将每个月的值扩展到 2021 年,但保留集合中最后一个月(2018 年第 7 个月)的先前值。
所需的输出将按地区、月份和年份附加到每个集合的末尾,例如:
2018 7 west 1 1
2018 7 east 9 9
2018 7 north 5 1
2018 8 west 1 1
2018 8 east 9 9
2018 8 north 5 1
2018 9 west 1 1
2018 9 east 9 9
2018 9 north 5 1
.
.
2019 7 west 1 1
2019 7 east 9 9
2019 7 north 5 1
.
.
2021 7 west 1 1
2021 7 east 9 9
2021 7 north 5 1
解决这个问题的最佳方法是什么?
【问题讨论】:
标签: python python-3.x pandas python-2.7 dataframe