-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata_cleaning.py
More file actions
22 lines (20 loc) · 886 Bytes
/
data_cleaning.py
File metadata and controls
22 lines (20 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def clean_data(data):
if "temperature" in data.columns:
data.loc[
(data["temperature"] >= 9999) | (data["temperature"] < -40), "temperature"
] = None
if "salinity" in data.columns:
data.loc[data["salinity"] >= 9999, "salinity"] = None
if "significant_height" in data.columns:
data.loc[data["significant_height"] >= 9999, "significant_height"] = None
if "latitude" in data.columns and "longitude" in data.columns:
# Drop rows where both latitude and longitude are 0
data = data.loc[~((data["latitude"] == 0) & (data["longitude"] == 0))]
data = data.dropna(subset=["latitude", "longitude"])
data = data.loc[
(data["latitude"] >= -90)
& (data["latitude"] <= 90)
& (data["longitude"] >= -180)
& (data["longitude"] <= 180)
]
return data