<jupyter_start><jupyter_text>Initial Database Exploraton  Import relevant libraries and load data<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import seaborn as sns
sns.set_theme(style="dark", color_codes=True)
sns.set_palette("mako")
plt.rcParams["figure.figsize"] = (25,5)
# Read in data in  sheet "RA Farm list December 2021" of the file

producers_data = pd.read_excel("../data/external/Certified-Farms-CoC-Operations-January-2022.xlsx", sheet_name="RA Farm list December 2021", header=2, usecols="A:S")
# Show first 5 rows

producers_data.head()<jupyter_output><empty_output><jupyter_text>Select Amazon Rainforest Countries<jupyter_code># Access only farms in: Brazil, Bolivia, Peru, Ecuador, Colombia, Venezuela, Guyana, Suriname

amazon_data = producers_data.loc[producers_data["Country"].isin(["Brazil", "Bolivia", "Peru", "Ecuador", "Colombia", "Venezuela", "Guyana", "Suriname"])]
amazon_data.head()
amazon_data.to_excel("../data/interim/MasterSyntheticDatabase_v0.xlsx")<jupyter_output><empty_output><jupyter_text>Data Analysis  Functions<jupyter_code>def NumberOfFarmsBarPlot(var_name, var_labels):
    n_per_var = []
    var_dataset = []

    for var in var_labels:
        var_data = amazon_data.loc[amazon_data[var_name] == var]
        var_dataset.append(var_data)
        n_per_var.append(len(var_data))

    print(n_per_var)

    plt.bar(var_labels, n_per_var)
    plt.show()
    
    return var_dataset

def CountBarPlot(labels, var_data, var_name):
    n_per_var = []

    for var in var_data:
        n_per_var.append(var[var_name].sum())

    print(n_per_var)

    plt.bar(labels, n_per_var)
    plt.rcParams["figure.figsize"] = (25,5)
    plt.ylabel(var_name)
    plt.show()
    
    return

def GenderWorkersBarPlot(var_data, labels):
    w_per_var = []
    fw_per_var = []
    mw_per_var = []

    for var in var_data:
        w_per_var.append(var["Total Workers"].sum())
        fw_per_var.append(var["Female workers"].sum())
        mw_per_var.append(var["Male Workers"].sum())

    print("Tot workers:", w_per_var)
    print("Female workers:", fw_per_var)
    print("Male workers:", mw_per_var)

    fig, ax = plt.subplots()
    ax.bar(labels, fw_per_var, label = "Female Workers", align='center')
    ax.bar(labels, mw_per_var, label = "Male Workers", bottom=fw_per_var, align='center')
    ax.set_ylabel("Total Workers")
    ax.legend()
    plt.show()
    
    return<jupyter_output><empty_output><jupyter_text>Workers Analysis<jupyter_code># Plot histograms of number of workers per farm
fig.tight_layout()
plt.hist(amazon_data["Total Workers"], bins=50)
plt.xlabel("Numer of Total Workers/Farm")
plt.show()

plt.hist(amazon_data["Female workers"], bins=50)
plt.xlabel("Numer of Female Workers/Farm")
plt.show()

plt.hist(amazon_data["Male Workers"], bins=50)
plt.xlabel("Numer of Male Workers/Farm")
plt.show()
amazon_data['Total Workers'].describe()<jupyter_output><empty_output><jupyter_text>Category Analysis<jupyter_code>categories = amazon_data["Category"].unique()
print(categories)
# Analyse number of farms per category

categories_data = NumberOfFarmsBarPlot("Category", categories)
# Analyse number of production hectares per category

CountBarPlot(categories, categories_data, "Production Hectares")
# Analyse volume of produce per category

CountBarPlot(categories, categories_data, "Volume")
# Analyse number and gender of workers per category

GenderWorkersBarPlot(categories_data, categories)<jupyter_output>Tot workers: [111387, 233657, 6405, 1182, 82, 6056, 156994, 1296, 80, 68]
Female workers: [60050, 77375, 2668, 445, 8, 639, 41677, 125, 22, 7]
Male workers: [51337, 156282, 3737, 737, 74, 5417, 115317, 1171, 58, 61]<jupyter_text>Country Analysis<jupyter_code>countries = amazon_data["Country"].unique()
print(countries)
# Analyse number of farms per country

countries_data = NumberOfFarmsBarPlot("Country", countries)
# Analyse number of production hectares per country

CountBarPlot(countries, countries_data, "Production Hectares")
# Analyse volume of produce per country

CountBarPlot(countries, countries_data, "Volume")
# Analyse number and gender of workers per country

GenderWorkersBarPlot(countries_data, countries)<jupyter_output>Tot workers: [52035, 56256, 142158, 265600, 1158]
Female workers: [13910, 16332, 58199, 94145, 430]
Male workers: [38125, 39924, 83959, 171455, 728]
{'fraction_non_alphanumeric': 0.12126696832579185, 'fraction_numerical': 0.04751131221719457, 'mean_word_length': 5.658132530120482, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '316102', 'license': 'FTL', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1510, 'n_words': 346, 'path': 'notebooks/1.0-cgb-initialdatabaseexploration.ipynb', 'repo_name': 'DE3Futures/forestDatabase', 'size': '4420'}