【发布时间】:2019-06-08 19:26:34
【问题描述】:
我正在使用 AI,并且有一个与一年中的时间相关的数据集。随着季节另一个词。温度、压力、湿度等。任务包括确定季节性收盘数据。我做了一些研究。附件代码中的详细信息。是否有任何通用的数据类型来表示季节,或者从天文学的角度来看可能是一天中的时间?
我已经尝试用三角函数 sin 和 cos 来表示数据。
# # The way to represent season.
import pandas as pd
import math
rng = pd.date_range('1/1/2011', periods=365*3, freq='D')
# Time of year is close to what I want, but...
rng[100+2].dayofyear - rng[100].dayofyear
# Out: 2
# ...in some cases it goes wrong:
# Only 2 days range. Almost no difference from the season point of
# view.
rng[364+2].dayofyear - rng[364].dayofyear
# Out: -363
# Yes, of couse, we still have a chance to fit AI to distinguish what
#'season' mean. But isn't it to complicate? In fact I want to
# reproduce some kind of astronomical data.
df = pd.DataFrame(index=rng, columns=('dayofyear','sin','cos'))
# Yes, I no this is not optimal. But this is just for visibility
for day in rng:
#print (day.dayofyear)
df.loc[day, 'dayofyear']=day.dayofyear
df.loc[day, 'sin'] = math.sin(day.dayofyear/365*2*math.pi)
df.loc[day, 'cos'] = math.cos(day.dayofyear/365*2*math.pi)
# Now, we can see something like season mean:
( df.loc['2012-01-01', 'sin'] - df.loc['2011-12-31', 'sin'] ) *
( df.loc['2012-01-01', 'cos'] - df.loc['2011-12-31', 'cos'] )
# Out: -2.5503444618122675e-06
( df.loc['2012-06-01', 'sin'] - df.loc['2011-12-31', 'sin'] ) *
( df.loc['2012-06-01', 'cos'] - df.loc['2011-12-31', 'cos'] )
# Out: -0.9111812528724549
# But, may be I just reinvent the bicycle?
# Is there a proper way to reproduce season and "Times of Day"?
【问题讨论】:
-
季节不是很普遍;例如,许多亚洲国家除了通常的四个雨季外,还承认雨季。英国每天经历四个季节。呜呜呜……
-
This answer 可能会有所帮助。
标签: python pandas data-representation