Python中的 时序分析

python
时间序列
数据分析
数据清洗
机器学习
利用pytimetk等进行时序分析、绘图及建模
作者

不止BI

发布于

2024年6月26日

数据准备

股票历史数据

代码
import adata
import numpy as np
import pandas as pd
# k_type: k线类型:1.日;2.周;3.月 默认:1 日k
df_stock_byday = pd.concat([adata.stock.market.get_market(stock_code='002241', k_type=1, start_date='2021-01-01').assign(stock_code='002241'),adata.stock.market.get_market(stock_code='000001', k_type=1, start_date='2021-01-01').assign(stock_code='000001')])


df_stock_byday[['open', 'close', 'volume', 'high', 'low']] = df_stock_byday[['open', 'close', 'volume', 'high', 'low']].astype(np.float64)

常用数据操作

查看数据结构

代码
import pytimetk as tk

df_stock_byday.glimpse()
<class 'pandas.core.frame.DataFrame'>: 1728 rows of 13 columns
trade_time:      object            ['2021-01-04 00:00:00', '2021-01-05 0 ...
trade_date:      object            ['2021-01-04', '2021-01-05', '2021-01 ...
open:            float64           [36.8, 35.94, 37.8, 37.29, 38.9, 38.6 ...
close:           float64           [36.19, 37.93, 37.13, 38.45, 38.69, 4 ...
high:            float64           [36.8, 38.35, 38.2, 38.95, 39.3, 41.1 ...
low:             float64           [35.85, 35.64, 36.85, 37.05, 37.73, 3 ...
volume:          float64           [1285439.0, 1675280.0, 953221.0, 1365 ...
amount:          float64           [4707993856.0, 6236502016.0, 36116663 ...
change_pct:      float64           [-1.58, 4.81, -2.11, 3.56, 0.62, 5.58 ...
change:          float64           [-0.58, 1.74, -0.8, 1.32, 0.24, 2.16, ...
turnover_ratio:  float64           [4.61, 6.01, 3.42, 4.89, 3.62, 6.23,  ...
pre_close:       float64           [36.769999999999996, 36.19, 37.93, 37 ...
stock_code:      object            ['002241', '002241', '002241', '00224 ...

转为日期格式

代码
df_stock_byday['trade_date'] = pd.to_datetime(df_stock_byday['trade_date'], format='%Y-%m-%d')
df_stock_byday['trade_time'] = pd.to_datetime(df_stock_byday['trade_time'], infer_datetime_format=True)

添加频率

Pandas 提供了多种频率字符串(也称为偏移别名)来定义时间序列的频率。以下是 Pandas 中使用的一些常见频率字符串:

  1. ‘B’:工作日

  2. ‘D’:日历日

  3. ‘W’:每周

  4. ‘M’:月末

  5. ‘BM’:营业月末

  6. ‘MS’:月份开始

  7. ‘BMS’:营业月份开始

  8. ‘Q’:季度末

  9. ‘BQ’:业务季度结束

  10. ‘QS’:季度开始

  11. ‘BQS’:业务季度开始

  12. ‘A’ 或 ‘Y’:年末

  13. “BA” 或 “BY”:业务年度结束

  14. ‘AS’ 或 ‘YS’:年份开始

  15. ‘BAS’ 或 ‘BYS’:营业年度开始

  16. ‘H’:每小时

  17. ‘T’ 或 ‘min’:每分钟

  18. ‘S’:其次

  19. ‘L’ 或 ‘ms’:毫秒

  20. ‘U’:微秒

  21. ‘N’:纳秒

自定义频率:

  • 您还可以通过组合基本频率来创建自定义频率,例如:

    • ‘2D’:每 2 天

    • ‘3W’:每 3 周

    • ‘4H’:每 4 小时

    • ‘1H30T’:每 1 小时 30 分钟

复合频率:

  • 您可以将多个频率相加在一起。

    • ‘1D1H’:1 天 1 小时

    • ‘1H30T’:1 小时 30 分钟

代码
date_range_two_days = pd.date_range(start='2023-01-01', end='2023-01-10', freq='1H30T')

date_range_two_days
DatetimeIndex(['2023-01-01 00:00:00', '2023-01-01 01:30:00',
               '2023-01-01 03:00:00', '2023-01-01 04:30:00',
               '2023-01-01 06:00:00', '2023-01-01 07:30:00',
               '2023-01-01 09:00:00', '2023-01-01 10:30:00',
               '2023-01-01 12:00:00', '2023-01-01 13:30:00',
               ...
               '2023-01-09 10:30:00', '2023-01-09 12:00:00',
               '2023-01-09 13:30:00', '2023-01-09 15:00:00',
               '2023-01-09 16:30:00', '2023-01-09 18:00:00',
               '2023-01-09 19:30:00', '2023-01-09 21:00:00',
               '2023-01-09 22:30:00', '2023-01-10 00:00:00'],
              dtype='datetime64[ns]', length=145, freq='90min')
代码
df_stock_byday = df_stock_byday.pad_by_time('trade_date', freq = 'B')
df_stock_byday.index.freq = 'B'
df_stock_byday.set_index(['trade_date'],inplace = True)
df_stock_byday.tail()
trade_time open close high low volume amount change_pct change turnover_ratio pre_close stock_code
trade_date
2024-07-24 2024-07-24 22.17 21.76 22.49 21.58 804468.0 1.763040e+09 -1.54 -0.34 2.67 22.10 002241
2024-07-25 2024-07-25 10.12 10.09 10.15 10.00 856404.0 8.617504e+08 -0.39 -0.04 0.44 10.13 000001
2024-07-25 2024-07-25 21.96 21.50 22.05 21.06 846324.0 1.812192e+09 -1.19 -0.26 2.81 21.76 002241
2024-07-26 2024-07-26 21.54 21.62 21.93 21.24 729641.0 1.572982e+09 0.56 0.12 2.42 21.50 002241
2024-07-26 2024-07-26 10.10 10.03 10.12 9.97 929552.0 9.318795e+08 -0.59 -0.06 0.48 10.09 000001

按频率统计

长表模式

代码
summary_stock_code_df = df_stock_byday \
    .groupby("stock_code") \
    .summarize_by_time(
        date_column  = 'trade_time', 
        value_column = 'close',
        freq         = "MS", 
        agg_func = ['mean', 'median', 'min', 'max'],
        wide_format  = False
    )


summary_stock_code_df.head()
stock_code trade_time close_mean close_median close_min close_max
0 000001 2021-01-01 19.837000 20.105 16.76 21.68
1 000001 2021-02-01 22.163333 22.440 19.97 23.54
2 000001 2021-03-01 20.079565 20.080 18.99 21.60
3 000001 2021-04-01 20.516667 20.270 18.85 22.18
4 000001 2021-05-01 22.591667 22.410 21.66 23.78

宽表模式

代码
df_stock_byday \
    .groupby("stock_code") \
    .summarize_by_time(
        date_column  = 'trade_time', 
        value_column = 'close',
        freq         = "MS",
        agg_func     = 'mean',
        wide_format  = True
    ). \
    head()
trade_time close_000001 close_002241
0 2021-01-01 19.837000 39.413500
1 2021-02-01 22.163333 32.794000
2 2021-03-01 20.079565 28.499565
3 2021-04-01 20.516667 31.700952
4 2021-05-01 22.591667 36.726111

生成时间特征

代码
df_stock_byday_with_sig = df_stock_byday.augment_timeseries_signature(date_column = 'trade_time')
df_stock_byday_with_sig.head()
trade_time open close high low volume amount change_pct change turnover_ratio ... trade_time_mday trade_time_qday trade_time_yday trade_time_weekend trade_time_hour trade_time_minute trade_time_second trade_time_msecond trade_time_nsecond trade_time_am_pm
trade_date
2021-01-04 2021-01-04 36.80 36.19 36.80 35.85 1285439.0 4.707994e+09 -1.58 -0.58 4.61 ... 4.0 4.0 4.0 0 0.0 0.0 0.0 0.0 0.0 am
2021-01-04 2021-01-04 17.69 17.19 17.69 17.03 1554216.0 2.891682e+09 -4.13 -0.74 0.80 ... 4.0 4.0 4.0 0 0.0 0.0 0.0 0.0 0.0 am
2021-01-05 2021-01-05 35.94 37.93 38.35 35.64 1675280.0 6.236502e+09 4.81 1.74 6.01 ... 5.0 5.0 5.0 0 0.0 0.0 0.0 0.0 0.0 am
2021-01-05 2021-01-05 16.99 16.76 17.07 16.39 1821352.0 3.284607e+09 -2.50 -0.43 0.94 ... 5.0 5.0 5.0 0 0.0 0.0 0.0 0.0 0.0 am
2021-01-06 2021-01-06 37.80 37.13 38.20 36.85 953221.0 3.611666e+09 -2.11 -0.80 3.42 ... 6.0 6.0 6.0 0 0.0 0.0 0.0 0.0 0.0 am

5 rows × 41 columns

生成滞后特征

代码
df_stock_byday \
  .groupby('stock_code') \
  .augment_lags(date_column = 'trade_time',value_column = 'close',lags = (1, 7)) \
  .head()
trade_time open close high low volume amount change_pct change turnover_ratio pre_close stock_code close_lag_1 close_lag_2 close_lag_3 close_lag_4 close_lag_5 close_lag_6 close_lag_7
trade_date
2021-01-04 2021-01-04 36.80 36.19 36.80 35.85 1285439.0 4.707994e+09 -1.58 -0.58 4.61 36.77 002241 NaN NaN NaN NaN NaN NaN NaN
2021-01-04 2021-01-04 17.69 17.19 17.69 17.03 1554216.0 2.891682e+09 -4.13 -0.74 0.80 17.93 000001 NaN NaN NaN NaN NaN NaN NaN
2021-01-05 2021-01-05 35.94 37.93 38.35 35.64 1675280.0 6.236502e+09 4.81 1.74 6.01 36.19 002241 36.19 NaN NaN NaN NaN NaN NaN
2021-01-05 2021-01-05 16.99 16.76 17.07 16.39 1821352.0 3.284607e+09 -2.50 -0.43 0.94 17.19 000001 17.19 NaN NaN NaN NaN NaN NaN
2021-01-06 2021-01-06 37.80 37.13 38.20 36.85 953221.0 3.611666e+09 -2.11 -0.80 3.42 37.93 002241 37.93 36.19 NaN NaN NaN NaN NaN

生成滚动窗口特征

代码
df_stock_byday \
  .groupby('stock_code') \
  .augment_rolling(
                date_column = 'trade_time',
                value_column = 'close',
                window = [2,7],
                window_func = ['mean', ('std', lambda x: x.std())]
            )
trade_time open close high low volume amount change_pct change turnover_ratio pre_close stock_code close_rolling_mean_win_2 close_rolling_std_win_2 close_rolling_mean_win_7 close_rolling_std_win_7
trade_date
2021-01-04 2021-01-04 17.69 17.19 17.69 17.03 1554216.0 2.891682e+09 -4.13 -0.74 0.80 17.93 000001 NaN NaN NaN NaN
2021-01-04 2021-01-04 36.80 36.19 36.80 35.85 1285439.0 4.707994e+09 -1.58 -0.58 4.61 36.77 002241 NaN NaN NaN NaN
2021-01-05 2021-01-05 16.99 16.76 17.07 16.39 1821352.0 3.284607e+09 -2.50 -0.43 0.94 17.19 000001 16.975 0.215 16.975000 0.215000
2021-01-05 2021-01-05 35.94 37.93 38.35 35.64 1675280.0 6.236502e+09 4.81 1.74 6.01 36.19 002241 37.060 0.870 37.060000 0.870000
2021-01-06 2021-01-06 16.67 18.15 18.15 16.59 1934945.0 3.648522e+09 8.29 1.39 1.00 16.76 000001 17.455 0.695 17.366667 0.581053
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2024-07-24 2024-07-24 10.18 10.13 10.24 10.12 724518.0 7.363328e+08 -0.49 -0.05 0.37 10.18 000001 10.155 0.025 10.288571 0.103016
2024-07-25 2024-07-25 21.96 21.50 22.05 21.06 846324.0 1.812192e+09 -1.19 -0.26 2.81 21.76 002241 21.630 0.130 22.440000 0.597351
2024-07-25 2024-07-25 10.12 10.09 10.15 10.00 856404.0 8.617504e+08 -0.39 -0.04 0.44 10.13 000001 10.110 0.020 10.258571 0.123800
2024-07-26 2024-07-26 10.10 10.03 10.12 9.97 929552.0 9.318795e+08 -0.59 -0.06 0.48 10.09 000001 10.060 0.030 10.205714 0.130915
2024-07-26 2024-07-26 21.54 21.62 21.93 21.24 729641.0 1.572982e+09 0.56 0.12 2.42 21.50 002241 21.560 0.060 22.231429 0.592342

1728 rows × 16 columns

生成未来日期

基于数据框

代码
df_stock_byday \
        .groupby('stock_code') \
        .future_frame('trade_time', length_out = 365) \
        .augment_timeseries_signature('trade_time') \
        .query("close.isna()") \
        .tail() 
trade_time open close high low volume amount change_pct change turnover_ratio ... trade_time_mday trade_time_qday trade_time_yday trade_time_weekend trade_time_hour trade_time_minute trade_time_second trade_time_msecond trade_time_nsecond trade_time_am_pm
2519 2025-07-22 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 22.0 22.0 203.0 0 0.0 0.0 0.0 0.0 0.0 am
2520 2025-07-23 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 23.0 23.0 204.0 0 0.0 0.0 0.0 0.0 0.0 am
2521 2025-07-24 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 24.0 24.0 205.0 0 0.0 0.0 0.0 0.0 0.0 am
2522 2025-07-25 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 25.0 25.0 206.0 0 0.0 0.0 0.0 0.0 0.0 am
2523 2025-07-26 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 26.0 26.0 207.0 0 0.0 0.0 0.0 0.0 0.0 am

5 rows × 41 columns

基于Series

代码
pd.Series(pd.date_range("2023", "2024", freq = "D")) \
  .make_future_timeseries(12) \
  .get_timeseries_signature()
idx idx_index_num idx_year idx_year_iso idx_yearstart idx_yearend idx_leapyear idx_half idx_quarter idx_quarteryear ... idx_mday idx_qday idx_yday idx_weekend idx_hour idx_minute idx_second idx_msecond idx_nsecond idx_am_pm
0 2024-01-02 1704153600 2024 2024 0 0 1 1 1 2024Q1 ... 2 2 2 0 0 0 0 0 0 am
1 2024-01-03 1704240000 2024 2024 0 0 1 1 1 2024Q1 ... 3 3 3 0 0 0 0 0 0 am
2 2024-01-04 1704326400 2024 2024 0 0 1 1 1 2024Q1 ... 4 4 4 0 0 0 0 0 0 am
3 2024-01-05 1704412800 2024 2024 0 0 1 1 1 2024Q1 ... 5 5 5 0 0 0 0 0 0 am
4 2024-01-06 1704499200 2024 2024 0 0 1 1 1 2024Q1 ... 6 6 6 0 0 0 0 0 0 am
5 2024-01-07 1704585600 2024 2024 0 0 1 1 1 2024Q1 ... 7 7 7 1 0 0 0 0 0 am
6 2024-01-08 1704672000 2024 2024 0 0 1 1 1 2024Q1 ... 8 8 8 0 0 0 0 0 0 am
7 2024-01-09 1704758400 2024 2024 0 0 1 1 1 2024Q1 ... 9 9 9 0 0 0 0 0 0 am
8 2024-01-10 1704844800 2024 2024 0 0 1 1 1 2024Q1 ... 10 10 10 0 0 0 0 0 0 am
9 2024-01-11 1704931200 2024 2024 0 0 1 1 1 2024Q1 ... 11 11 11 0 0 0 0 0 0 am
10 2024-01-12 1705017600 2024 2024 0 0 1 1 1 2024Q1 ... 12 12 12 0 0 0 0 0 0 am
11 2024-01-13 1705104000 2024 2024 0 0 1 1 1 2024Q1 ... 13 13 13 0 0 0 0 0 0 am

12 rows × 30 columns

数据观察

绘制折线图观察每日收盘价趋势

代码
df_stock_byday['year'] = pd.to_datetime(df_stock_byday['trade_time']).dt.year
df_stock_byday. \
  reset_index(). \
  dropna(). \
  groupby("stock_code"). \
  plot_timeseries(date_column  = 'trade_time',
  facet_ncol = 2, 
  color_column = 'year',
  facet_scales = "free",
  value_column = 'close')

针对股票时序数据可以绘制k线图

代码
from datetime import datetime

import vectorbt as vbt

df_stock_byday = adata.stock.market.get_market(stock_code='002241', k_type=1, start_date='2021-01-01').assign(stock_code='002241')

df_stock_byday[['open', 'close', 'volume', 'high', 'low']] = df_stock_byday[['open', 'close', 'volume', 'high', 'low']].astype(np.float64)

df_stock_byday['trade_date'] = pd.to_datetime(df_stock_byday['trade_date'], format='%Y-%m-%d')
df_stock_byday['trade_time'] = pd.to_datetime(df_stock_byday['trade_time'], infer_datetime_format=True)
plot_Candlestick = df_stock_byday.vbt.ohlcv.plot(plot_type='Candlestick')
plot_Candlestick.update_layout(height=None,width=None)
plot_Candlestick.show()

异常值检测

代码
df_stock_byday  = df_stock_byday.loc[df_stock_byday.stock_code == '002241']
# df_stock_byday = df_stock_byday.pad_by_time('trade_time', freq = 'B')  # 按工作日重采样,缺失的日期的值用NA填补  
# df_stock_byday.set_index(['trade_time'],inplace = True)
# df_stock_byday.index.freq = 'B'

anomalize_df = tk.anomalize(
    data          = df_stock_byday,
    date_column   = 'trade_time',
    value_column  = 'close',
    period        = 7,
    iqr_alpha     = 0.05, # using the default
    clean_alpha   = 0.75, # using the default
    clean         = "min_max"
)

anomalize_df.glimpse()
<class 'pandas.core.frame.DataFrame'>: 864 rows of 12 columns
trade_time:         datetime64[ns]    [Timestamp('2021-01-04 00:00:00'), ...
observed:           float64           [36.19, 37.93, 37.13, 38.45, 38.69 ...
seasonal:           float64           [4.797307111756358, -2.89055462491 ...
seasadj:            float64           [31.39269288824364, 40.82055462491 ...
trend:              float64           [41.13074580232775, 40.88098513275 ...
remainder:          float64           [-9.738052914084111, -0.0604305078 ...
anomaly:            object            ['Yes', 'No', 'No', 'No', 'No', 'N ...
anomaly_score:      float64           [10.492364565686895, 0.81474215944 ...
anomaly_direction:  int32             [-1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, ...
recomposed_l1:      float64           [42.16966810551952, 34.23204569928 ...
recomposed_l2:      float64           [51.19506102585427, 43.25743861961 ...
observed_clean:     float64           [43.297842220561364, 37.93, 37.13, ...

绘制异常值

代码
# Plot anomalies
tk.plot_anomalies(
    data        = anomalize_df,
    date_column = 'trade_time',
    engine      = 'plotly',
    title       = '异常值'
)

清理异常值后

代码
tk.plot_anomalies_cleaned(
    data        = anomalize_df,
    date_column = 'trade_time',
    engine      = 'plotly',
    title       = '清理异常值后'
)

绘制季节分解图

时间序列分解是一种将时间序列分解为多个组成部分的统计方法,每个组成部分代表模式的基本类别之一。这些组成部分通常包括:

  • 趋势 (T):长期上升或下降的趋势

  • 季节性 (S):在一年或更短的时间内重复出现的周期性波动

  • 周期性 (C):比季节性更长的周期性波动

  • 不规则性 (I):随机的、不可预测的变化

代码
tk.plot_anomalies_decomp(
    data        = anomalize_df,
    date_column = 'trade_time',
    engine      = 'plotly',
    title       = '时间序列分解'
)

时间序列模型

单变量时间序列模型 多变量时间序列模型
只使用一个变量 使用多个变量
无法使用外部数据 可以使用外部数据
仅基于过去和现在之间的关系 基于过去和现在之间的关系,以及变量之间的关系
预测未来某个时间点该变量的值 预测未来某个时间点一个或多个变量的值

随机森林

代码
import pandas as pd
import numpy as np
import pytimetk as tk

from sklearn.ensemble import RandomForestRegressor


df_stock_byday.glimpse()
dset = tk.load_dataset('walmart_sales_weekly', parse_dates = ['Date'])

dset = dset.drop(columns=[
    'id', # This column can be removed as it is equivalent to 'Dept'
    'Store', # This column has only one possible value
    'Type', # This column has only one possible value
    'Size', # This column has only one possible value
    'MarkDown1', 'MarkDown2', 'MarkDown3', 'MarkDown4', 'MarkDown5',
    'IsHoliday', 'Temperature', 'Fuel_Price', 'CPI',
       'Unemployment'])

dset.head()
sales_df = dset
sales_df_with_futureframe = sales_df \
    .groupby('Dept') \
    .future_frame(
        date_column = 'Date',
        length_out  = 5
    )
    
sales_df_dates = sales_df_with_futureframe.augment_timeseries_signature(date_column = 'Date')
sales_df_dates.head(10)


df_with_lags = sales_df_dates \
    .groupby('Dept') \
    .augment_lags(
        date_column  = 'Date',
        value_column = 'Weekly_Sales',
        lags         = [5,6,7,8,9]
    )
    
lag_columns = [col for col in df_with_lags.columns if 'lag' in col]

df_with_rolling = df_with_lags \
    .groupby('Dept') \
    .augment_rolling(
        date_column  = 'Date',
        value_column = lag_columns,
        window  = 4,
        window_func = 'mean',
        threads = 1 # Change to -1 to use all available cores
    ) 
df_with_rolling[df_with_rolling.Dept ==1].head(10)
df_with_lags.head(5)

all_lag_columns = [col for col in df_with_rolling.columns if 'lag' in col]

df_no_nas = df_with_rolling \
    .dropna(subset=all_lag_columns, inplace=False)

df_no_nas.head()

future = df_no_nas[df_no_nas.Weekly_Sales.isnull()]
train = df_no_nas[df_no_nas.Weekly_Sales.notnull()]


train_columns = [ 
    'Dept'
    , 'Date_year'
    , 'Date_month'
    , 'Date_yweek'
    , 'Date_mweek'
    , 'Weekly_Sales_lag_5'
    , 'Weekly_Sales_lag_6'
    , 'Weekly_Sales_lag_7'
    , 'Weekly_Sales_lag_8'
    , 'Weekly_Sales_lag_5_rolling_mean_win_4'
    , 'Weekly_Sales_lag_6_rolling_mean_win_4'
    , 'Weekly_Sales_lag_7_rolling_mean_win_4'
    , 'Weekly_Sales_lag_8_rolling_mean_win_4'
    ]

X = train[train_columns]
y = train[['Weekly_Sales']]

model = RandomForestRegressor(random_state=123)
model = model.fit(X, y)

predicted_values = model.predict(future[train_columns])
future['y_pred'] = predicted_values

future.head(10)

train['type'] = 'actuals'
future['type'] = 'prediction'

full_df = pd.concat([train, future])

full_df.head(10)

full_df['Weekly_Sales'] = np.where(full_df.type =='actuals', full_df.Weekly_Sales, full_df.y_pred)

full_df \
    .groupby('Dept') \
    .plot_timeseries(
        date_column = 'Date',
        value_column = 'Weekly_Sales',
        color_column = 'type',
        smooth = False,
        smooth_alpha = 0,
        facet_ncol = 2,
        facet_scales = "free",
        y_intercept_color = tk.palette_timetk()['steel_blue'],
        width = 800,
        height = 600,
        engine = 'plotly'
    )
<class 'pandas.core.frame.DataFrame'>: 864 rows of 13 columns
trade_time:      datetime64[ns]    [Timestamp('2021-01-04 00:00:00'), Ti ...
trade_date:      datetime64[ns]    [Timestamp('2021-01-04 00:00:00'), Ti ...
open:            float64           [36.8, 35.94, 37.8, 37.29, 38.9, 38.6 ...
close:           float64           [36.19, 37.93, 37.13, 38.45, 38.69, 4 ...
high:            float64           [36.8, 38.35, 38.2, 38.95, 39.3, 41.1 ...
low:             float64           [35.85, 35.64, 36.85, 37.05, 37.73, 3 ...
volume:          float64           [1285439.0, 1675280.0, 953221.0, 1365 ...
amount:          float64           [4707993856.0, 6236502016.0, 36116663 ...
change_pct:      float64           [-1.58, 4.81, -2.11, 3.56, 0.62, 5.58 ...
change:          float64           [-0.58, 1.74, -0.8, 1.32, 0.24, 2.16, ...
turnover_ratio:  float64           [4.61, 6.01, 3.42, 4.89, 3.62, 6.23,  ...
pre_close:       float64           [36.769999999999996, 36.19, 37.93, 37 ...
stock_code:      object            ['002241', '002241', '002241', '00224 ...
代码
# !pip install git+https://github.com/business-science/pymodeltime.git
# 
# !pip install autogluon
# 
# 
# !pip install h2o
回到顶部