获取年份范围和特定月份的十进制格式
Obtaining decimal format for range of years and specific months
我有月度数据(1993 - 2019),但我希望得到 1993 - 2019 中只有七月、八月和九月的十进制格式。
以下是 1993 年至 2019 年(所有 12 个月)之间十进制格式的月份代码,但希望得到相同的结果,但仅适用于 7 月、8 月和 9 月:
year_start = 1993
year_end = 2019
full_time_months = np.arange(year_start+.5/12,year_end+1,1/12)
print(full_time_months[:12])
# these are the 12 months in 1993 as decimals
1993.04166667 1993.125 1993.20833333 1993.29166667 1993.375
1993.45833333 1993.54166667 1993.625 1993.70833333 1993.79166667
1993.875 1993.95833333
我的目标是只获取 7 月、8 月和 9 月的数组:
1993.54167、1993.625、1993.708...2019.54167、2019.625、2019.708
其中 year.54167 = 七月,year.625 = 八月,year.708 = 九月。
我该怎么做呢?希望我的问题足够清楚,如果有不清楚的地方请评论,谢谢!!!
我不确定你想用这个实现什么,但你可以这样做,分离你想要的数据。
import numpy as np
year_start = 1993
year_end = 2019
full_time_months = np.arange(year_start+.5/12,year_end+1,1/12)
# Reshape into 2D array
full_time_months = full_time_months.reshape(-1, 12)
# Choose selected columns
# July, Aug, Sept
selected_months = full_time_months[:, [6,7,8]]
print(selected_months)
结果:
[[1993.54166667 1993.625 1993.70833333]
[1994.54166667 1994.625 1994.70833333]
...
[2018.54166667 2018.625 2018.70833333]
[2019.54166667 2019.625 2019.70833333]]
我有月度数据(1993 - 2019),但我希望得到 1993 - 2019 中只有七月、八月和九月的十进制格式。
以下是 1993 年至 2019 年(所有 12 个月)之间十进制格式的月份代码,但希望得到相同的结果,但仅适用于 7 月、8 月和 9 月:
year_start = 1993
year_end = 2019
full_time_months = np.arange(year_start+.5/12,year_end+1,1/12)
print(full_time_months[:12])
# these are the 12 months in 1993 as decimals
1993.04166667 1993.125 1993.20833333 1993.29166667 1993.375
1993.45833333 1993.54166667 1993.625 1993.70833333 1993.79166667
1993.875 1993.95833333
我的目标是只获取 7 月、8 月和 9 月的数组:
1993.54167、1993.625、1993.708...2019.54167、2019.625、2019.708
其中 year.54167 = 七月,year.625 = 八月,year.708 = 九月。
我该怎么做呢?希望我的问题足够清楚,如果有不清楚的地方请评论,谢谢!!!
我不确定你想用这个实现什么,但你可以这样做,分离你想要的数据。
import numpy as np
year_start = 1993
year_end = 2019
full_time_months = np.arange(year_start+.5/12,year_end+1,1/12)
# Reshape into 2D array
full_time_months = full_time_months.reshape(-1, 12)
# Choose selected columns
# July, Aug, Sept
selected_months = full_time_months[:, [6,7,8]]
print(selected_months)
结果:
[[1993.54166667 1993.625 1993.70833333]
[1994.54166667 1994.625 1994.70833333]
...
[2018.54166667 2018.625 2018.70833333]
[2019.54166667 2019.625 2019.70833333]]