我正在与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"?
答案 0 :(得分:0)
据我所知,时间戳记的数据类型或时间模块中未确认季节。
您可以做的是写一个Forumala来评估日期,并确定它属于哪个季节。