考虑到不同产品的时间序列分配

发布于 2025-02-13 15:55:31 字数 333 浏览 3 评论 0原文

我有多种产品的DF(PANDA)包含时间数据(见下文)。这些产品可能在与其他产品的日期相同的日期开始或结束(例如Prod 1和2系列在DN之前完成,而Prod 4在D3和DN之间开始的某个位置)。考虑到每个产品,我想进行时间序列分开。这样,根据产品,我可以在培训和测试上拥有相同的日期。我该怎么做?

date  prod  value
d1    p1    10
d1    p2    10
d2    p1    15
d2    p2    12
d3    p1    8
d3    p2    5
d3    p3    7
.
dn    p2    20
dn    p4    10

I have df (pandas) containing temporal data for several products (see below). The products may not start or finish in the same date as the others (eg. prod 1 and 2 series finished before dn, while prod 4 started somewhere between d3 and dn). I want to do a time series split, taking into account each produt. By doing that, I can have the same date on training and test, depending on the product. How do I do that?

date  prod  value
d1    p1    10
d1    p2    10
d2    p1    15
d2    p2    12
d3    p1    8
d3    p2    5
d3    p3    7
.
dn    p2    20
dn    p4    10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2025-02-20 15:55:32

您可以使用:

d = {prod: group.set_index('date')['value'] for prod, group in df.groupby('prod')}

如果所有产品都具有相同的索引:

d = {prod: group.set_index('date')['value'].reindex(df['date'].unique()) 
     for prod, group in df.groupby('prod')}

you could use:

d = {prod: group.set_index('date')['value'] for prod, group in df.groupby('prod')}

if you want all products have the same index:

d = {prod: group.set_index('date')['value'].reindex(df['date'].unique()) 
     for prod, group in df.groupby('prod')}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文