我有月度資料(1993 - 2019),但我希望獲得 1993 - 2019 年僅 7 月、8 月和 9 月的十進制格式。
以下是 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 = 九月。
我該怎么做呢?希望我的問題足夠清楚,如果有不清楚的地方請評論,謝謝!!!
uj5u.com熱心網友回復:
我不確定你想用這個實作什么,但你可以做這樣的事情,來分離你想要的資料。
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]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369820.html
