plotting datasets in hv, also better split with dropna

This commit is contained in:
wassname
2020-10-31 18:12:58 +08:00
parent 9a7f2f018c
commit d6d47b87e6
7 changed files with 14254 additions and 25355 deletions
+13 -3
View File
@@ -13,7 +13,17 @@ def normalize_encode_dataframe(df, encoder=OrdinalEncoder):
df_norm = scaler.fit_transform(df)
return df_norm, scaler
def timeseries_split(df, test_fraction=0.2):
def timeseries_split(df, test_fraction=0.2, dropna=None):
"""Split timeseries data with test in the future"""
i = int(len(df)*test_fraction)
return df.iloc[:-i], df.iloc[-i:]
# If there are lots of nan's we can ignore them when splitting into portions
if isinstance(dropna, list):
index = df.dropna(subset=dropna).index
elif dropna is True:
index = df.dropna().index
else:
index = df.index
i = int(len(index)*test_fraction)
dt = index.values[i]
return df.loc[:dt], df.loc[dt:]