-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutlierRemove.py
More file actions
37 lines (30 loc) · 1.45 KB
/
Copy pathoutlierRemove.py
File metadata and controls
37 lines (30 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def outlierRemove(data,function):
'''
This function is to remove the outliers of the data. Assisted by ChatGPT.
Interquartile Range (IQR) Method:
The Interquartile Range is the range between the first quartile (25th percentile) and
the third quartile (75th percentile) of a dataset. Outliers can be identified by values
that fall below the first quartile minus a threshold or above the third quartile plus the threshold.
Typically, a threshold of 1.5 times the IQR is used.
Input : data = output returning from functions that calculate flow properties
function = flow properties that we want to calculate
'''
import pandas as pd
import numpy as np
data = data
if function == 'Rxy':
function = 'uv_prime'
if function == 'Rxx':
function = 'uu_prime'
if function == 'Ryy':
function = 'vv_prime'
# Calculate the first and third quartiles (25th and 75th percentiles)
q1 = data[0].reset_index()[function].quantile(0.25)
q3 = data[0].reset_index()[function].quantile(0.75)
# Calculate the IQR (Interquartile Range)
iqr = q3 - q1
# Set an IQR threshold (e.g., 1.5 times the IQR)
iqr_threshold = 1.5
# Remove outliers by filtering based on the IQR
data_without_outliers = data[0].reset_index()[(data[0].reset_index()[function] >= q1 - iqr_threshold * iqr) & (data[0].reset_index()[function] <= q3 + iqr_threshold * iqr)]
return data_without_outliers