poor man's branch

This commit is contained in:
lda committed 2025-05-06 17:32:23 +07:00
1 parent 8f599bd2f0
commit b04a4704a5
4 files changed
+5709 -5617

No files matched your search

+3
View File
@@ -14,6 +14,9 @@ how to git? do not `push --force`. prefer pull requests. its like github
we will plan to do this in multiple different ways using scikit-learn and pytorch. tensorflow is ancient. we will plan to do this in multiple different ways using scikit-learn and pytorch. tensorflow is ancient.
> [!IMPORTANT]
> phase out tensorflow. dont use it.
maybe also fit more weather related stats? this dataset is taken from nasa so sources are there maybe also fit more weather related stats? this dataset is taken from nasa so sources are there
## collab ## collab
+5625 -5615
View File
File diff suppressed because it is too large. Load diff
+79
View File
@@ -0,0 +1,79 @@
"extracting the load data step from the notebook"
import io
# from itertools import islice
from typing import Union
import pandas as pd
def cut_headers(stream: Union[io.StringIO, io.FileIO, io.TextIOWrapper]):
headers = []
exist_startheader = False
while line := stream.readline():
if "-BEGIN HEADER-" in line and not exist_startheader:
exist_startheader = True
headers.append(str(line.strip()))
elif "-END HEADER-" in line and exist_startheader:
headers.append(str(line.strip()))
break
elif exist_startheader:
# print(f"{line = }")
headers.append(str(line.strip()))
elif not exist_startheader:
continue
if not exist_startheader:
# If no headers are found, reset the stream and return
stream.seek(0)
return "", stream
return "\n".join(headers), stream
# if __name__ == "__main__":
# with open("hanoi_qv2m_latest.csv", "r", encoding="utf-8") as file:
# header, file = cut_headers(file)
# print("Extracted Header:")
# print(header)
# data = pd.read_csv(file)
# print("\nFirst 5 Lines of Data:")
# print(data.head())
# print(data.isnull().sum())
def load_data(
weather_file_name, columns=["Year", "Month", "Day", "Humidity"].copy(), na=-999
):
with open(weather_file_name, "r", encoding="utf-8") as file:
_header, file = cut_headers(file)
data = pd.read_csv(file, na_values=na)
# print(header)
data.columns = columns
return data
def date_combine(data: pd.DataFrame):
data["Date"] = pd.to_datetime(data[["Year", "Month", "Day"]])
data = data.drop(columns=["Year", "Month", "Day"])
data = data.set_index("Date")
return data
def validate_view(data: pd.DataFrame):
print(f"Shape with N/A values: {data.shape}")
isn = data.isnull().sum().iloc[0]
print(f"Count of N/A values: {isn}")
data = data.dropna() # Drop the rows with missing values
isn = data.isnull().sum().iloc[0]
print(f"Count after drop: {isn}")
print(data.describe())
return data
# if __name__ == "__main__":
def load_this_data(filename):
d = load_data(filename)
d = date_combine(d)
d = validate_view(d)
return d
+2 -2
View File
@@ -1139,7 +1139,7 @@
"provenance": [] "provenance": []
}, },
"kernelspec": { "kernelspec": {
"display_name": ".venv", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -1153,7 +1153,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.9" "version": "3.9.18"
} }
}, },
"nbformat": 4, "nbformat": 4,