Timestamp
1990-2022
Data source
Dataset
modified_flourish_wide_format_countries_with_flags.csv
Protocol
Flourish + Python
Preprocessing steps:
- 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).