Skip to content

Commit

Permalink
handling nordic (æøå), data cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
torave committed Mar 30, 2025
1 parent 704d63f commit 2d9de07
Showing 1 changed file with 152 additions and 7 deletions.
159 changes: 152 additions & 7 deletions notebooks/notebook_current_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data fetch: ok\n"
]
}
],
"source": [
"import sys\n",
"import os\n",
Expand All @@ -35,6 +43,12 @@
"# User input the city, for the weather\n",
"city_name = input(\"Enter a city in Norway: \")\n",
"\n",
"for letter in city_name:\n",
" if letter in 'æøå':\n",
" city_name = city_name.replace('æ', 'ae')\n",
" city_name = city_name.replace('ø', 'o')\n",
" city_name = city_name.replace('å', 'aa')\n",
"\n",
"# Stores the return of the function\n",
"data, folder = fetch_current_data(city_name)"
]
Expand All @@ -54,9 +68,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data has been written to /Users/toravestlund/Documents/ITBAITBEDR/TDT4114 - Anvendt programmering/anvendt_mappe/data/../data/output_current_data/data_aaa_maura.json\n"
]
}
],
"source": [
"# Gets the absolute path to the src folder\n",
"sys.path.append(os.path.abspath(\"../src\"))\n",
Expand All @@ -81,9 +103,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'coord': {'lon': 11.0167, 'lat': 60.25},\n",
" 'weather': [{'id': 500,\n",
" 'main': 'Rain',\n",
" 'description': 'light rain',\n",
" 'icon': '10d'}],\n",
" 'base': 'stations',\n",
" 'main': {'temp': 3.14,\n",
" 'temp_min': 2.52,\n",
" 'temp_max': 3.84,\n",
" 'humidity': 93,\n",
" 'sea_level': 1003,\n",
" 'grnd_level': 965},\n",
" 'visibility': 10000,\n",
" 'wind': {'speed': 1.54, 'deg': 70},\n",
" 'rain': {'1h': 0.11},\n",
" 'clouds': {'all': 75},\n",
" 'dt': 1743329160,\n",
" 'sys': {'type': 1,\n",
" 'id': 1624,\n",
" 'country': 'NO',\n",
" 'sunrise': 1743309996,\n",
" 'sunset': 1743357233},\n",
" 'timezone': 7200,\n",
" 'id': 3146270,\n",
" 'name': 'Maura',\n",
" 'cod': 200}"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import json\n",
"\n",
Expand Down Expand Up @@ -118,7 +175,92 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>name</th>\n",
" <th>main.temp</th>\n",
" <th>main.humidity</th>\n",
" <th>main.sea_level</th>\n",
" <th>main.grnd_level</th>\n",
" <th>wind.speed</th>\n",
" <th>rain.1h</th>\n",
" <th>clouds.all</th>\n",
" <th>sys.country</th>\n",
" <th>sys.sunrise</th>\n",
" <th>sys.sunset</th>\n",
" </tr>\n",
" <tr>\n",
" <th>dt</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2025-03-30 10:06:00</th>\n",
" <td>Maura</td>\n",
" <td>3.14</td>\n",
" <td>93</td>\n",
" <td>1003</td>\n",
" <td>965</td>\n",
" <td>1.54</td>\n",
" <td>0.11</td>\n",
" <td>75</td>\n",
" <td>NO</td>\n",
" <td>2025-03-30 04:46:36</td>\n",
" <td>2025-03-30 17:53:53</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name main.temp main.humidity main.sea_level \\\n",
"dt \n",
"2025-03-30 10:06:00 Maura 3.14 93 1003 \n",
"\n",
" main.grnd_level wind.speed rain.1h clouds.all \\\n",
"dt \n",
"2025-03-30 10:06:00 965 1.54 0.11 75 \n",
"\n",
" sys.country sys.sunrise sys.sunset \n",
"dt \n",
"2025-03-30 10:06:00 NO 2025-03-30 04:46:36 2025-03-30 17:53:53 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"\n",
Expand Down Expand Up @@ -151,6 +293,9 @@
"df['dt'] = pd.to_datetime(df['dt'], unit='s')\n",
"df.set_index('dt', inplace=True)\n",
"\n",
"# Drops the whole column, if all values is 'NaN' value.\n",
"df = df.dropna(axis='columns', how='all')\n",
"\n",
"# Display the df after changes\n",
"display(df)"
]
Expand Down

0 comments on commit 2d9de07

Please sign in to comment.