1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-09 05:50:59 +08:00

add Handler Storage

This commit is contained in:
bxdd
2021-06-28 20:06:15 +00:00
parent 27f0db669f
commit e1b6f310c9
7 changed files with 115 additions and 22 deletions

View File

@@ -1,5 +1,8 @@
from typing import Union
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import pandas as pd
from typing import Union, List
def get_level_index(df: pd.DataFrame, level=Union[str, int]) -> int:
@@ -72,6 +75,17 @@ def fetch_df_by_index(
]
def fetch_df_by_col(df: pd.DataFrame, col_set: Union[str, List[str]]) -> pd.DataFrame:
from .handler import DataHandler
if not isinstance(df.columns, pd.MultiIndex) or col_set == DataHandler.CS_RAW:
return df
elif col_set == DataHandler.CS_ALL:
return df.droplevel(axis=1, level=0)
else:
return df.loc(axis=1)[col_set]
def convert_index_format(df: Union[pd.DataFrame, pd.Series], level: str = "datetime") -> Union[pd.DataFrame, pd.Series]:
"""
Convert the format of df.MultiIndex according to the following rules: