From 1f3afb408bf9e638e406af7f3b090fa811c93584 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 1 Mar 2019 17:12:31 +1100 Subject: [PATCH] Resample quality codes with first value (not mean) --- waternsw_grabber/waternsw_grabber.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/waternsw_grabber/waternsw_grabber.py b/waternsw_grabber/waternsw_grabber.py index 5bb1959..4d10ab9 100644 --- a/waternsw_grabber/waternsw_grabber.py +++ b/waternsw_grabber/waternsw_grabber.py @@ -464,15 +464,27 @@ def extract_records(input_dir, output_dir, clean_up=False): # Get basin ID basin_code = sites.loc[bore_id, 'Basin code'] + # Make copy of original dataframe + df_all = df.copy() + + # Get quality columns + q_idx = ['Quality' in col for col in df.columns] + # Resample if necessary for period in periods: if period == 'daily': # Resample to daily timestamps - df = df.resample('1d').mean() + df = df_all.resample('1d').mean() + # Get first quality code for each period, as mean doesn't work + q_val = df_all.loc[:, q_idx].resample('1d').first() + df.loc[:, q_idx] = q_val elif period == 'weekly': # Resample to weekly timestamps - df = df.resample('1w').mean() + df = df_all.resample('1w').mean() + # Get first quality code for each period, as mean doesn't work + q_val = df_all.loc[:, q_idx].resample('1w').first() + df.loc[:, q_idx] = q_val # Add specific borehole details df['Site'] = sites.loc[bore_id, 'Site']