This project explores the role of pesticides in agriculture and their impact on global trade. It provides an informative and interactive webpage that highlights:
- What pesticides are and how they work.
- Their importance in protecting crops from pests, diseases, and weeds.
- Their role in ensuring global food security and enhancing agricultural productivity.
- Load the dataset: Read the original CSV file (
original_merged.csv) into a Pandas DataFrame. - Select relevant columns: Identify and keep only the necessary columns:
Area,Year,Fungicides and Bactericides,Herbicides,Insecticides,Other Pesticides nes,Pesticides (total),Plant Growth Regulators, andRodenticides. - Filter the dataset: Remove all columns not listed in the
columns_to_keeplist to retain only relevant data. - Save the transformed dataset: Write the filtered dataset to a new CSV file (
cleaned_dataset.csv).
- Load the dataset: Read the CSV file (
modified_tableau_wide_format_countries_with_flags.csv) into a Pandas DataFrame. - Map countries to continents: Create a new
Continentcolumn by mapping country names in theAreacolumn to their corresponding continent using thecountry_to_continentdictionary. - Drop missing mappings: Remove rows where the
Continentmapping is missing (i.e.,NaNin theContinentcolumn). - Aggregate data by continent: Group the dataset by the
Continentcolumn and sum all numeric columns. - Save the transformed dataset: Write the aggregated dataset to a new CSV file at the specified output path.
- Load the Dataset: Read the CSV file (
cleaned_dataset.csv) into a Pandas DataFrame. - Reshape with Melt: Use the
meltfunction to reshape the DataFrame. IncludeAreaandYearas identifier columns (id_vars) and transform selected pesticide-related columns (value_vars) into a long format withPesticide TypeandUsagecolumns. - Filter Rows: Exclude rows where the
Pesticide Typecolumn equals'Pesticides (total)'. - Harmonize Country Names: Replace
China, mainlandandMainlandin theAreacolumn withChina. - Pivot Data: Transform the long-format DataFrame into a wide format with
Areaas rows andYearas columns. AggregateUsagevalues using thesumfunction. - Generate Flag URLs: Create a dictionary mapping country names to their flag URLs using the ISO codes provided.
- Map Flag URLs: Add a
Flag URLcolumn to the DataFrame by mapping theAreacolumn to the flag URL dictionary. - Save Transformed Data: Write the transformed dataset with flag URLs to a new CSV file (
modified_tableau_wide_format_countries_with_flags.csv).
- Load the Dataset: Read the CSV file (
cleaned_dataset.csv) into a Pandas DataFrame. - Reshape with Melt: Use the
meltfunction to reshape the DataFrame. KeepYearas the identifier column (id_vars) and transform selected pesticide-related columns (value_vars) into a long format withPesticide TypeandUsagecolumns. - Filter Rows: Exclude rows where the
Pesticide Typecolumn equals'Pesticides (total)'. - Pivot Data: Transform the long-format DataFrame back into a wide format with
Yearas rows andPesticide Typeas columns. Aggregate usage values using thesumfunction. - Save Transformed Data: Write the transformed dataset to a new CSV file (
modified_tableau_long_format_exclude_total.csv).
The project includes the following components:
- The main structure of the webpage is in
index.html. - Key sections:
- Titles and subtitles introducing the theme.
- Informative content with highlighted keywords.
- Images and captions for better understanding.
- Custom styling to ensure a clean, responsive, and visually appealing design.
- Key features:
- Background images and color themes.
- Responsive layout optimized for desktop and mobile devices.
- Hover effects for interactivity.
- Images and other static resources are stored in the
assets/folder.
- Located in the
preprocessing/folder:dataset_cleaner.py: Script for cleaning and preprocessing raw datasets.extract_countries.py: Script for mapping all the countries
SUPSI
Bachelor in Data Science and Artificial Intelligence
Teacher: Giovanni Profeta
https://dataviz-supsi.github.io/2024/