Skip to main content
 首页 » 编程设计

python之Django Python 时间序列之可重用的应用程序和数据库模式

2025年05月04日6lyhabc

建议使用哪些 Django 应用程序或 Python 模块来处理和保存到数据库时间序列数据。时间序列数据推荐使用哪种数据库模式?

我的用例是我的数据库模式中有节点模型具有开始日期和结束日期,我想为开始日期和结束日期之间的每一天保存一个值。这可能有很多行,因为我有数千个节点,开始日期和结束日期在 1 到 365 天之间。

我的模型看起来像这样,而我将感谢有关更好/性能改进结构的输入:

class Node(models.Model): 
    """ 
    Representation of a single node 
    """ 
 
    name = models.CharField(max_length=200) 
    start = models.DateField()  
    end = models.DateField() 
 
class TimeSeries(models.Model) 
     """ 
     holds the time series values. For each day between start and end date one TimeSeries object will be created 
     """ 
     node = models.ForeignKey(Node) 
     date = models.DateField() #holds a specific date between start and end date of node 
     value = models.IntegerField(max_length=2) 

请您参考如下方法:

我会说你最好的选择是 Pandas。他们充分利用 NumPy、scikits 等并将其打包。

  1. Pandas' Time Series functionality .即使 pyTseries 不再活跃(合并到 Pandas 中),documentation is good to browse .
  2. 如果对 ARMA 感兴趣,请查看这些“statsmodels”集。

希望这对您有所帮助。