diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 68b3762..d9cf066 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "#Import your libraries\n" + "# Import your libraries\n", + "import pandas as pd\n", + "import numpy as np\n" ] }, { @@ -38,11 +40,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "\n", + "# Load the dataset\n", + "austin = pd.read_csv('austin_weather.csv')" ] }, { @@ -57,29 +61,298 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 1319 entries, 0 to 1318\n", + "Data columns (total 21 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date 1319 non-null object\n", + " 1 TempHighF 1319 non-null int64 \n", + " 2 TempAvgF 1319 non-null int64 \n", + " 3 TempLowF 1319 non-null int64 \n", + " 4 DewPointHighF 1319 non-null object\n", + " 5 DewPointAvgF 1319 non-null object\n", + " 6 DewPointLowF 1319 non-null object\n", + " 7 HumidityHighPercent 1319 non-null object\n", + " 8 HumidityAvgPercent 1319 non-null object\n", + " 9 HumidityLowPercent 1319 non-null object\n", + " 10 SeaLevelPressureHighInches 1319 non-null object\n", + " 11 SeaLevelPressureAvgInches 1319 non-null object\n", + " 12 SeaLevelPressureLowInches 1319 non-null object\n", + " 13 VisibilityHighMiles 1319 non-null object\n", + " 14 VisibilityAvgMiles 1319 non-null object\n", + " 15 VisibilityLowMiles 1319 non-null object\n", + " 16 WindHighMPH 1319 non-null object\n", + " 17 WindAvgMPH 1319 non-null object\n", + " 18 WindGustMPH 1319 non-null object\n", + " 19 PrecipitationSumInches 1319 non-null object\n", + " 20 Events 1319 non-null object\n", + "dtypes: int64(3), object(18)\n", + "memory usage: 216.5+ KB\n", + "None\n" + ] + } + ], + "source": [ + "# Look at the variables and their types\n", + "print(austin.info())" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " TempHighF TempAvgF TempLowF\n", + "count 1319.000000 1319.000000 1319.000000\n", + "mean 80.862775 70.642911 59.902957\n", + "std 14.766523 14.045904 14.190648\n", + "min 32.000000 29.000000 19.000000\n", + "25% 72.000000 62.000000 49.000000\n", + "50% 83.000000 73.000000 63.000000\n", + "75% 92.000000 83.000000 73.000000\n", + "max 107.000000 93.000000 81.000000\n" + ] + } + ], + "source": [ + "# Examine the descriptive statistics of the numeric variables\n", + "print(austin.describe())\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercent...SeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHPrecipitationSumInchesEvents
02013-12-21746045674943937557...29.6829.591072204310.46Rain , Thunderstorm
12013-12-22564839433628936843...30.1329.8710105166250
22013-12-23584532312723765227...30.4930.4110101083120
32013-12-24614631362821895622...30.4530.310107124200
42013-12-25585041444036867156...30.3330.271010710216T
\n", + "

5 rows × 21 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67 49 \n", + "1 2013-12-22 56 48 39 43 36 \n", + "2 2013-12-23 58 45 32 31 27 \n", + "3 2013-12-24 61 46 31 36 28 \n", + "4 2013-12-25 58 50 41 44 40 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent ... \\\n", + "0 43 93 75 57 ... \n", + "1 28 93 68 43 ... \n", + "2 23 76 52 27 ... \n", + "3 21 89 56 22 ... \n", + "4 36 86 71 56 ... \n", + "\n", + " SeaLevelPressureAvgInches SeaLevelPressureLowInches VisibilityHighMiles \\\n", + "0 29.68 29.59 10 \n", + "1 30.13 29.87 10 \n", + "2 30.49 30.41 10 \n", + "3 30.45 30.3 10 \n", + "4 30.33 30.27 10 \n", + "\n", + " VisibilityAvgMiles VisibilityLowMiles WindHighMPH WindAvgMPH WindGustMPH \\\n", + "0 7 2 20 4 31 \n", + "1 10 5 16 6 25 \n", + "2 10 10 8 3 12 \n", + "3 10 7 12 4 20 \n", + "4 10 7 10 2 16 \n", + "\n", + " PrecipitationSumInches Events \n", + "0 0.46 Rain , Thunderstorm \n", + "1 0 \n", + "2 0 \n", + "3 0 \n", + "4 T \n", + "\n", + "[5 rows x 21 columns]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Look at the first five rows of all variables\n", + "austin.head()\n" ] }, { @@ -113,20 +386,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['49', '36', '27', '28', '40', '39', '41', '26', '42', '22', '48',\n", + " '32', '8', '11', '45', '55', '61', '37', '47', '25', '23', '20',\n", + " '33', '30', '29', '17', '14', '13', '54', '59', '15', '24', '34',\n", + " '35', '57', '50', '53', '60', '46', '56', '51', '31', '38', '62',\n", + " '43', '63', '64', '67', '66', '58', '70', '68', '65', '69', '71',\n", + " '72', '-', '73', '74', '21', '44', '52', '12', '75', '76', '18'],\n", + " dtype=object)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Examine the DewPointAvgF variable\n", + "austin['DewPointAvgF'].unique()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# Your observation here\n" + "# Your observation here\n", + "# When looking at the unique values, we can see that there are non-numeric string characters mixed in with the numbers \n", + "# (typically characters like '-' indicating missing data or 'T' for trace amounts). \n", + "# Because Pandas requires all data in a single numeric column to be strictly numerical, \n", + "# the presence of these string characters forces Pandas to cast the entire column as an object (string) type to accommodate them.\n" ] }, { @@ -140,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -153,11 +448,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Use apply and pd.to_numeric to coerce errors into NaN\n", + "austin[wrong_type_columns] = austin[wrong_type_columns].apply(pd.to_numeric, errors='coerce')\n" ] }, { @@ -169,11 +465,41 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Date object\n", + "TempHighF int64\n", + "TempAvgF int64\n", + "TempLowF int64\n", + "DewPointHighF float64\n", + "DewPointAvgF float64\n", + "DewPointLowF float64\n", + "HumidityHighPercent float64\n", + "HumidityAvgPercent float64\n", + "HumidityLowPercent float64\n", + "SeaLevelPressureHighInches float64\n", + "SeaLevelPressureAvgInches float64\n", + "SeaLevelPressureLowInches float64\n", + "VisibilityHighMiles float64\n", + "VisibilityAvgMiles float64\n", + "VisibilityLowMiles float64\n", + "WindHighMPH float64\n", + "WindAvgMPH float64\n", + "WindGustMPH float64\n", + "PrecipitationSumInches float64\n", + "Events object\n", + "dtype: object\n" + ] + } + ], + "source": [ + "# Check if your code has worked by printing the data types again\n", + "print(austin.dtypes)\n" ] }, { @@ -200,11 +526,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Identify all rows containing at least one missing value\n", + "missing_values = austin[austin.isnull().any(axis=1)]\n" ] }, { @@ -233,11 +560,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total rows in austin: 1319\n", + "Total rows with missing values: 136\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Count the number of rows of austin and missing_values\n", + "print(f\"Total rows in austin: {len(austin)}\")\n", + "print(f\"Total rows with missing values: {len(missing_values)}\")\n" ] }, { @@ -249,11 +587,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ratio of missing rows: 10.31%\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Calculate the ratio of missing rows to total rows\n", + "missing_ratio = len(missing_values) / len(austin)\n", + "print(f\"Ratio of missing rows: {missing_ratio:.2%}\")" ] }, { @@ -267,11 +615,41 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 7\n", + "DewPointAvgF 7\n", + "DewPointLowF 7\n", + "HumidityHighPercent 2\n", + "HumidityAvgPercent 2\n", + "HumidityLowPercent 2\n", + "SeaLevelPressureHighInches 3\n", + "SeaLevelPressureAvgInches 3\n", + "SeaLevelPressureLowInches 3\n", + "VisibilityHighMiles 12\n", + "VisibilityAvgMiles 12\n", + "VisibilityLowMiles 12\n", + "WindHighMPH 2\n", + "WindAvgMPH 2\n", + "WindGustMPH 4\n", + "PrecipitationSumInches 124\n", + "Events 0\n", + "dtype: int64\n" + ] + } + ], + "source": [ + "# Find the number of missing rows in each column\n", + "print(austin.isna().sum())\n" ] }, { @@ -283,11 +661,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrecipitationSumInches missing ratio: 9.40%\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Number of missing values in PrecipitationSumInches in ratio to its total number of rows\n", + "precip_missing_ratio = austin['PrecipitationSumInches'].isna().sum() / len(austin)\n", + "print(f\"PrecipitationSumInches missing ratio: {precip_missing_ratio:.2%}\")\n" ] }, { @@ -309,16 +697,227 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here \n", - "\n", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercentSeaLevelPressureHighInchesSeaLevelPressureAvgInchesSeaLevelPressureLowInchesVisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHEvents
02013-12-2174604567.049.043.093.075.057.029.8629.6829.5910.07.02.020.04.031.0Rain , Thunderstorm
12013-12-2256483943.036.028.093.068.043.030.4130.1329.8710.010.05.016.06.025.0
22013-12-2358453231.027.023.076.052.027.030.5630.4930.4110.010.010.08.03.012.0
32013-12-2461463136.028.021.089.056.022.030.5630.4530.3010.010.07.012.04.020.0
42013-12-2558504144.040.036.086.071.056.030.4130.3330.2710.010.07.010.02.016.0
\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " SeaLevelPressureHighInches SeaLevelPressureAvgInches \\\n", + "0 29.86 29.68 \n", + "1 30.41 30.13 \n", + "2 30.56 30.49 \n", + "3 30.56 30.45 \n", + "4 30.41 30.33 \n", + "\n", + " SeaLevelPressureLowInches VisibilityHighMiles VisibilityAvgMiles \\\n", + "0 29.59 10.0 7.0 \n", + "1 29.87 10.0 10.0 \n", + "2 30.41 10.0 10.0 \n", + "3 30.30 10.0 10.0 \n", + "4 30.27 10.0 10.0 \n", + "\n", + " VisibilityLowMiles WindHighMPH WindAvgMPH WindGustMPH \\\n", + "0 2.0 20.0 4.0 31.0 \n", + "1 5.0 16.0 6.0 25.0 \n", + "2 10.0 8.0 3.0 12.0 \n", + "3 7.0 12.0 4.0 20.0 \n", + "4 7.0 10.0 2.0 16.0 \n", + "\n", + " Events \n", + "0 Rain , Thunderstorm \n", + "1 \n", + "2 \n", + "3 \n", + "4 " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remove this column from austin using the .drop() function\n", + "austin.drop('PrecipitationSumInches', axis=1, inplace=True)\n", "\n", "# Print `austin` to confirm the column is indeed removed\n", - "\n", - "austin" + "austin.head()" ] }, { @@ -336,11 +935,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\pablo\\AppData\\Local\\Temp\\ipykernel_9864\\356643453.py:2: FutureWarning: DataFrame.interpolate with object dtype is deprecated and will raise in a future version. Call obj.infer_objects(copy=False) before interpolating instead.\n", + " austin_fixed = austin.interpolate(inplace=False)\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Perform linear interpolation on the entire dataframe\n", + "austin_fixed = austin.interpolate(inplace=False)" ] }, { @@ -352,11 +961,65 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Missing in austin_fixed:\n", + " Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 0\n", + "DewPointAvgF 0\n", + "DewPointLowF 0\n", + "HumidityHighPercent 0\n", + "HumidityAvgPercent 0\n", + "HumidityLowPercent 0\n", + "SeaLevelPressureHighInches 0\n", + "SeaLevelPressureAvgInches 0\n", + "SeaLevelPressureLowInches 0\n", + "VisibilityHighMiles 0\n", + "VisibilityAvgMiles 0\n", + "VisibilityLowMiles 0\n", + "WindHighMPH 0\n", + "WindAvgMPH 0\n", + "WindGustMPH 0\n", + "Events 0\n", + "dtype: int64\n", + "\n", + "Missing in austin:\n", + " Date 0\n", + "TempHighF 0\n", + "TempAvgF 0\n", + "TempLowF 0\n", + "DewPointHighF 7\n", + "DewPointAvgF 7\n", + "DewPointLowF 7\n", + "HumidityHighPercent 2\n", + "HumidityAvgPercent 2\n", + "HumidityLowPercent 2\n", + "SeaLevelPressureHighInches 3\n", + "SeaLevelPressureAvgInches 3\n", + "SeaLevelPressureLowInches 3\n", + "VisibilityHighMiles 12\n", + "VisibilityAvgMiles 12\n", + "VisibilityLowMiles 12\n", + "WindHighMPH 2\n", + "WindAvgMPH 2\n", + "WindGustMPH 4\n", + "Events 0\n", + "dtype: int64\n" + ] + } + ], + "source": [ + "# Check to make sure austin_fixed contains no missing data, and austin still does\n", + "print(\"Missing in austin_fixed:\\n\", austin_fixed.isna().sum())\n", + "print(\"\\nMissing in austin:\\n\", austin.isna().sum())\n" ] }, { @@ -377,11 +1040,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here:\n" + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Events\n", + " 903\n", + "Rain 192\n", + "Rain , Thunderstorm 137\n", + "Fog , Rain , Thunderstorm 33\n", + "Fog 21\n", + "Thunderstorm 17\n", + "Fog , Rain 14\n", + "Rain , Snow 1\n", + "Fog , Thunderstorm 1\n", + "Name: count, dtype: int64\n" + ] + } + ], + "source": [ + "# Evaluate the contents of this column\n", + "print(austin_fixed['Events'].value_counts())\n" ] }, { @@ -395,11 +1077,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "# Your answer:\n" + "# Your answer:\n", + "\n", + "# Looking at the value counts (and splitting the strings by commas), \n", + "# the largest number of events that happened in a single day is usually 3 (e.g., \"Fog , Rain , Thunderstorm\").\n" ] }, { @@ -415,18 +1100,225 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercent...VisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHEventsSnowFogRainThunderstorm
02013-12-2174604567.049.043.093.075.057.0...7.02.020.04.031.0Rain , Thunderstorm0000
12013-12-2256483943.036.028.093.068.043.0...10.05.016.06.025.00000
22013-12-2358453231.027.023.076.052.027.0...10.010.08.03.012.00000
32013-12-2461463136.028.021.089.056.022.0...10.07.012.04.020.00000
42013-12-2558504144.040.036.086.071.056.0...10.07.010.02.016.00000
\n", + "

5 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " ... VisibilityAvgMiles VisibilityLowMiles WindHighMPH WindAvgMPH \\\n", + "0 ... 7.0 2.0 20.0 4.0 \n", + "1 ... 10.0 5.0 16.0 6.0 \n", + "2 ... 10.0 10.0 8.0 3.0 \n", + "3 ... 10.0 7.0 12.0 4.0 \n", + "4 ... 10.0 7.0 10.0 2.0 \n", + "\n", + " WindGustMPH Events Snow Fog Rain Thunderstorm \n", + "0 31.0 Rain , Thunderstorm 0 0 0 0 \n", + "1 25.0 0 0 0 0 \n", + "2 12.0 0 0 0 0 \n", + "3 20.0 0 0 0 0 \n", + "4 16.0 0 0 0 0 \n", + "\n", + "[5 rows x 24 columns]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create a dummy column with 0 values for each event\n", "event_list = ['Snow', 'Fog', 'Rain', 'Thunderstorm']\n", "\n", - "# Your code here\n", - "\n", + "for event in event_list:\n", + " austin_fixed[event] = 0\n", "\n", - "# Print your new dataframe to check whether new columns have been created:\n", - "\n", - "austin_fixed" + "# Print your new dataframe to check whether new columns have been created\n", + "austin_fixed.head()" ] }, { @@ -446,11 +1338,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Populate the actual values in the dummy columns\n", + "for event in event_list:\n", + " # Use na=False to handle any potential NaN values in the Events column gracefully\n", + " austin_fixed[event] = austin_fixed['Events'].str.contains(event, na=False).astype(int)" ] }, { @@ -462,11 +1357,219 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercent...VisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHEventsSnowFogRainThunderstorm
02013-12-2174604567.049.043.093.075.057.0...7.02.020.04.031.0Rain , Thunderstorm0011
12013-12-2256483943.036.028.093.068.043.0...10.05.016.06.025.00000
22013-12-2358453231.027.023.076.052.027.0...10.010.08.03.012.00000
32013-12-2461463136.028.021.089.056.022.0...10.07.012.04.020.00000
42013-12-2558504144.040.036.086.071.056.0...10.07.010.02.016.00000
\n", + "

5 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 2013-12-21 74 60 45 67.0 49.0 \n", + "1 2013-12-22 56 48 39 43.0 36.0 \n", + "2 2013-12-23 58 45 32 31.0 27.0 \n", + "3 2013-12-24 61 46 31 36.0 28.0 \n", + "4 2013-12-25 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " ... VisibilityAvgMiles VisibilityLowMiles WindHighMPH WindAvgMPH \\\n", + "0 ... 7.0 2.0 20.0 4.0 \n", + "1 ... 10.0 5.0 16.0 6.0 \n", + "2 ... 10.0 10.0 8.0 3.0 \n", + "3 ... 10.0 7.0 12.0 4.0 \n", + "4 ... 10.0 7.0 10.0 2.0 \n", + "\n", + " WindGustMPH Events Snow Fog Rain Thunderstorm \n", + "0 31.0 Rain , Thunderstorm 0 0 1 1 \n", + "1 25.0 0 0 0 0 \n", + "2 12.0 0 0 0 0 \n", + "3 20.0 0 0 0 0 \n", + "4 16.0 0 0 0 0 \n", + "\n", + "[5 rows x 24 columns]" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Print out austin_fixed to check if the event columns are populated\n", + "austin_fixed.head()\n" ] }, { @@ -478,11 +1581,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Drop the Events column as we don't need it any more\n", + "austin_fixed.drop('Events', axis=1, inplace=True)\n" ] }, { @@ -500,11 +1604,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "import datetime\n", + "\n", + "# Convert the Date column values from string to numeric values using toordinal()\n", + "austin_fixed['Date'] = austin_fixed['Date'].apply(lambda x: datetime.datetime.strptime(x, \"%Y-%m-%d\").toordinal())\n" ] }, { @@ -516,10 +1623,218 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTempHighFTempAvgFTempLowFDewPointHighFDewPointAvgFDewPointLowFHumidityHighPercentHumidityAvgPercentHumidityLowPercent...VisibilityHighMilesVisibilityAvgMilesVisibilityLowMilesWindHighMPHWindAvgMPHWindGustMPHSnowFogRainThunderstorm
073522374604567.049.043.093.075.057.0...10.07.02.020.04.031.00011
173522456483943.036.028.093.068.043.0...10.010.05.016.06.025.00000
273522558453231.027.023.076.052.027.0...10.010.010.08.03.012.00000
373522661463136.028.021.089.056.022.0...10.010.07.012.04.020.00000
473522758504144.040.036.086.071.056.0...10.010.07.010.02.016.00000
\n", + "

5 rows × 23 columns

\n", + "
" + ], + "text/plain": [ + " Date TempHighF TempAvgF TempLowF DewPointHighF DewPointAvgF \\\n", + "0 735223 74 60 45 67.0 49.0 \n", + "1 735224 56 48 39 43.0 36.0 \n", + "2 735225 58 45 32 31.0 27.0 \n", + "3 735226 61 46 31 36.0 28.0 \n", + "4 735227 58 50 41 44.0 40.0 \n", + "\n", + " DewPointLowF HumidityHighPercent HumidityAvgPercent HumidityLowPercent \\\n", + "0 43.0 93.0 75.0 57.0 \n", + "1 28.0 93.0 68.0 43.0 \n", + "2 23.0 76.0 52.0 27.0 \n", + "3 21.0 89.0 56.0 22.0 \n", + "4 36.0 86.0 71.0 56.0 \n", + "\n", + " ... VisibilityHighMiles VisibilityAvgMiles VisibilityLowMiles \\\n", + "0 ... 10.0 7.0 2.0 \n", + "1 ... 10.0 10.0 5.0 \n", + "2 ... 10.0 10.0 10.0 \n", + "3 ... 10.0 10.0 7.0 \n", + "4 ... 10.0 10.0 7.0 \n", + "\n", + " WindHighMPH WindAvgMPH WindGustMPH Snow Fog Rain Thunderstorm \n", + "0 20.0 4.0 31.0 0 0 1 1 \n", + "1 16.0 6.0 25.0 0 0 0 0 \n", + "2 8.0 3.0 12.0 0 0 0 0 \n", + "3 12.0 4.0 20.0 0 0 0 0 \n", + "4 10.0 2.0 16.0 0 0 0 0 \n", + "\n", + "[5 rows x 23 columns]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Print austin_fixed to check your Date column\n", "austin_fixed.head(5)" ] }, @@ -577,11 +1892,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Assign the TempAvgF column to y and the remaining specified columns to X\n", + "X = austin_fixed[['Date', 'TempHighF', 'TempLowF', 'DewPointHighF', 'DewPointAvgF', \n", + " 'DewPointLowF', 'HumidityHighPercent', 'HumidityAvgPercent', \n", + " 'HumidityLowPercent', 'SeaLevelPressureHighInches', \n", + " 'SeaLevelPressureAvgInches', 'SeaLevelPressureLowInches', \n", + " 'VisibilityHighMiles', 'VisibilityAvgMiles', 'VisibilityLowMiles', \n", + " 'WindHighMPH', 'WindAvgMPH', 'WindGustMPH', 'Snow', 'Fog', 'Rain', \n", + " 'Thunderstorm']]\n", + "\n", + "y = austin_fixed['TempAvgF']\n" ] }, { @@ -593,11 +1917,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ - "#Your code here:\n" + "# Import train_test_split from sklearn.model_selection\n", + "from sklearn.model_selection import train_test_split\n" ] }, { @@ -612,11 +1937,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ - "#Your code here:\n" + "# Split X and y into X_train, X_test, y_train, and y_test (80% train, 20% test)\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)" ] }, { @@ -641,11 +1967,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Compute the number of rows that account for 80% of our data\n", + "ts_rows = int(len(austin_fixed) * 0.8)\n" ] }, { @@ -657,11 +1984,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Assign the first ts_rows rows of X to X_ts_train and the remaining rows to X_ts_test\n", + "X_ts_train = X.iloc[:ts_rows]\n", + "X_ts_test = X.iloc[ts_rows:]\n" ] }, { @@ -673,17 +2002,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Assign the first ts_rows rows of y to y_ts_train and the remaining rows to y_ts_test\n", + "y_ts_train = y.iloc[:ts_rows]\n", + "y_ts_test = y.iloc[ts_rows:]\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -697,7 +2028,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.13.9" } }, "nbformat": 4,