如何打印数据框的开始和结束日期?
How I can print the start and end dates of a data frame?
我有这些代码行,当我 运行 它时,我想像这样查看训练、验证和测试的日期:
2012-01-01 00:00:00 --- 2013-12-31 23:00:00:00
而不是指数:
20150 --- 20189
datos = df_energy.loc['2015-07-02 01:00:00': '2021-11-30 15:00:00']
fin_train = '2019-12-31 23:59:00'
fin_validacion = '2020-11-30 23:59:00'
datos_train = datos.loc[:fin_train, :]
datos_val = datos.loc[fin_train: fin_validacion, :]
datos_test = datos.loc[fin_validacion:, :]
print(f"Fechas train : {datos_train.index.min()} --- {datos_train.index.max()}")
print(f"Fechas validacion : {datos_val.index.min()} --- {datos_val.index.max()}")
print(f"Fechas test : {datos_test.index.min()} --- {datos_test.index.max()}")
您已经有了索引,只需使用它们来获取相关值即可。我将为示例性的火车数据这样做,然后您可以将其同等地转移到其他数据集:
def gen_timerange(df, col='UTC Time'):
min_time = df.loc[df.index.min(), col]
max_time = df.loc[df.index.max(), col]
return f"{min_time} --- {max_time}"
print(f"Fechas train : {gen_timerange(datos_train)}")
我有这些代码行,当我 运行 它时,我想像这样查看训练、验证和测试的日期:
2012-01-01 00:00:00 --- 2013-12-31 23:00:00:00
而不是指数:
20150 --- 20189
datos = df_energy.loc['2015-07-02 01:00:00': '2021-11-30 15:00:00']
fin_train = '2019-12-31 23:59:00'
fin_validacion = '2020-11-30 23:59:00'
datos_train = datos.loc[:fin_train, :]
datos_val = datos.loc[fin_train: fin_validacion, :]
datos_test = datos.loc[fin_validacion:, :]
print(f"Fechas train : {datos_train.index.min()} --- {datos_train.index.max()}")
print(f"Fechas validacion : {datos_val.index.min()} --- {datos_val.index.max()}")
print(f"Fechas test : {datos_test.index.min()} --- {datos_test.index.max()}")
您已经有了索引,只需使用它们来获取相关值即可。我将为示例性的火车数据这样做,然后您可以将其同等地转移到其他数据集:
def gen_timerange(df, col='UTC Time'):
min_time = df.loc[df.index.min(), col]
max_time = df.loc[df.index.max(), col]
return f"{min_time} --- {max_time}"
print(f"Fechas train : {gen_timerange(datos_train)}")