<jupyter_start><jupyter_text>Activity 1.02: Forest fire size and temperature analysis In this activity, you will consolidate the skills you've acquired in the last exercise and use NumPy to do some very basic mathematical calculations on our `normal_distribution` dataset.   NumPy has a consistent API, so it should be rather easy to transfer your knowledge of the mean method to median and variance.   Loading the dataset<jupyter_code># importing the necessary dependencies
import pandas as pd
# loading the Dataset
dataset = pd.read_csv('./Datasets/forestfires.csv')
# looking at the first two rows of the dataset
dataset[0:2]<jupyter_output><empty_output><jupyter_text>The dataset contains: - X - x-axis spatial coordinate within the Montesinho park map: 1 to 9 - Y - y-axis spatial coordinate within the Montesinho park map: 2 to 9 - **month - month of the year: 'jan' to 'dec'**- day - day of the week: 'mon' to 'sun' - FFMC - FFMC index from the FWI system: 18.7 to 96.20 - DMC - DMC index from the FWI system: 1.1 to 291.3 - DC - DC index from the FWI system: 7.9 to 860.6 - ISI - ISI index from the FWI system: 0.0 to 56.10 - **temp - temperature in Celsius degrees: 2.2 to 33.30**- RH - relative humidity in %: 15.0 to 100 - wind - wind speed in km/h: 0.40 to 9.40 - rain - outside rain in mm/m2 : 0.0 to 6.4 - **area - the burned area of the forest (in ha): 0.00 to 1090.84****Note:**   The fields that we'll be working with are highlighted in the listing. ---  Getting insights into the sizes of forest fires.When looking at the first two rows of our dataset we can already see that it contains entries in which the area is 0.    For this first task we only care about fires that have an area of more than 0.   Create a new dataset that only contains the entries with an area value of > 0.<jupyter_code># filter the dataset for rows that have an area > 0
area_dataset= dataset[dataset["area"] > 0]

area_dataset<jupyter_output><empty_output><jupyter_text>After filtering out the zero area entries, we can simply use the `mean` method of pandas to get the mean area size of the forest fires for the filtered down dataset not containing zero area sizes.Get the mean value for the `area` column of out filtered dataset.<jupyter_code># get the mean value for the area column
area_dataset["area"].mean()<jupyter_output><empty_output><jupyter_text>In addition to that, looking at the largest and smallest non-zero area can help us understand the range of possible area sizes.Let's get more insights into that.- Use the `min` and `max` methods to see the smallest and largest area that has been affected by a forest fire.- Use the `std` method to get insights into how much variation there is in our dataset.<jupyter_code># get the smallest area value from our dataset
area_dataset["area"].min()
# get the largest area value from our dataset
area_dataset["area"].max()
# get the standard deviation of values in our dataset
area_dataset["area"].std()<jupyter_output><empty_output><jupyter_text>The largest value is much larger than our mean.   The standard deviation also is quite large which indicates that the difference between our mean and the "middle value" will be quite high.Let's look at the last 20 values of our sorted dataset to see if we have more than one very large value.   Sort the filtered dataset by the `area` column and output the last 20 entries from it.<jupyter_code># sorting the filtered dataset and printing the last 20 elements 
area_dataset.sort_values(by=["area"]).tail(20)<jupyter_output><empty_output><jupyter_text>As we can see here, only 11 out of the 270 rows contain values that are larger than 100.   After 20 values we are close to the area value of 60. Let's imagine our dataset contained only 1 or 2 values that were much higher than the other ones, e.g. an area size value of 10254.91. Simply by observing the dataset, this feels like there might have been an error on adding this to the dataset.   In a smaller dataset, the mean value would get heavily distored by this one entry. A more stable value to use in such a case is the median value of the dataset.Get the median value for the ´area´ column.<jupyter_code># calculate the median value for the area column
area_dataset["area"].median()<jupyter_output><empty_output><jupyter_text>**Note:**   Remember that the median is not the same as then mean of your dataset. While the median is simple the "value in the middle", the mean is much more prone to distortion by outliers. ---  Finding the month with the most forest fires In this second task we want to quickly see which months have the most forest fires and whether or not the temperature has a direct connection to it.Get a list of month values that are present in our dataset.<jupyter_code># get a list of month values from the dataset
months = dataset["month"].unique()

months<jupyter_output><empty_output><jupyter_text>In addition to the unique values we also want use the shape element of our dataset to determine how many rows it has.Filter the dataset for only rows that contain the month `mar` and print the number of rows using `shape`.<jupyter_code># get the number of forest fires for the month of march
dataset[dataset["month"] == "mar"].shape[0]<jupyter_output><empty_output><jupyter_text>The last step to fulfil the task is to iterate over all months, filtering our dataset for the rows containing the given month and calculating the mean temperature.- Iterate over the months from the unique list we created- Filter our dataset for the rows containing the given month- Get the number of rows from `shape`- Get the mean temperature for the given month- Print a statement with the number of fires, mean temperature and the month<jupyter_code># iterate over the months list
# get number of forest fires for each month
# get mean temperature for each month
# print out number of fires and mean temperature
for month in months:
    month_dataset = dataset[dataset["month"] == month]
    fires_in_month = month_dataset.shape[0]
    avg_tmp_in_month = int(month_dataset["temp"].mean())
    
    print(str(fires_in_month) + " fires in " + month + " with a mean temperature of ~" + str(avg_tmp_in_month) + "°C")<jupyter_output>54 fires in mar with a mean temperature of ~13°C
15 fires in oct with a mean temperature of ~17°C
184 fires in aug with a mean temperature of ~21°C
172 fires in sep with a mean temperature of ~19°C
9 fires in apr with a mean temperature of ~12°C
17 fires in jun with a mean temperature of ~20°C
32 fires in jul with a mean temperature of ~22°C
20 fires in feb with a mean temperature of ~9°C
2 fires in jan with a mean temperature of ~5°C
9 fires in dec with a mean temperature of ~4°C
2 fires in may with a mean temperature of ~14°C
1 fires in nov with a mean temperature of ~11°C
{'fraction_non_alphanumeric': 0.06370085722731303, 'fraction_numerical': 0.021282885013301802, 'mean_word_length': 4.417934347477982, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '247074', 'license': 'MIT', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1794, 'n_words': 1036, 'path': 'Chapter01/Activity1.02/Activity1.02.ipynb', 'repo_name': 'jgoerner/Data-Visualization-with-Python', 'size': '6766'}