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
melt
function to reshape the DataFrame. IncludeArea
andYear
as identifier columns (id_vars
) and transform selected pesticide-related columns (value_vars
) into a long format withPesticide Type
andUsage
columns. - Filter Rows: Exclude rows where the
Pesticide Type
column equals'Pesticides (total)'
. - Harmonize Country Names: Replace
China, mainland
andMainland
in theArea
column withChina
. - Pivot Data: Transform the long-format DataFrame into a wide format with
Area
as rows andYear
as columns. AggregateUsage
values using thesum
function. - Generate Flag URLs: Create a dictionary mapping country names to their flag URLs using the ISO codes provided.
- Map Flag URLs: Add a
Flag URL
column to the DataFrame by mapping theArea
column 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
).