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']