有季节的数据类型吗?

2024-04-25 06:48:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我和人工智能一起工作,得到了一个与一年中的时间相关的数据集。用另一个词。温度、压力、湿度等。任务包括确定季节性关闭数据。我做了些调查。详情见所附代码。从天文学的角度来看,是否有任何共同的数据类型来表示季节和一天中的时间?你知道吗

我已经试过用三角函数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"?

Tags: ofto数据dfismathsincos
1条回答
网友
1楼 · 发布于 2024-04-25 06:48:20

据我所知,season在timestamp的数据类型或time模块中没有被确认。你知道吗

你能做的就是写一个forumala来评估日期,并确定它属于哪个季节。你知道吗

相关问题 更多 >

    热门问题