{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/miniconda3/envs/hackathon/lib/python3.13/site-packages/fuzzywuzzy/fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning\n", " warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')\n" ] } ], "source": [ "import pandas as pd\n", "from fuzzywuzzy import process\n", "from typing import List\n", "\n", "\n", "def get_popular_agriculture(\n", " df: pd.DataFrame,\n", " region: str,\n", " surface_parc: str = None,\n", " groups_agri: List[str] = None,\n", "): # surface en hectare\n", " unique_regions = df[\"REGION\"].unique().tolist()\n", " region, _ = process.extractOne(region, unique_regions)\n", " df = df[df[\"REGION\"] == region]\n", " if groups_agri != None:\n", " unique_agri_group = df[\"LIBELLE_GROUPE_CULTURE\"].unique().tolist()\n", " groups_agri_new = []\n", " for group_culture in groups_agri:\n", " groups_agri_new.append(process.extractOne(group_culture, unique_agri_group)[0])\n", " df = df[df[\"LIBELLE_GROUPE_CULTURE\"].isin(groups_agri_new)]\n", " if surface_parc != None:\n", " popular_cultures = df[\"LIBELLE_CULTURE\"].value_counts().head(10).index\n", " df = df[df[\"LIBELLE_CULTURE\"].isin(popular_cultures)]\n", " df[\"proximity\"] = abs(df[\"SURF_PARC\"] - surface_parc)\n", " sorted_df = df.sort_values(by=\"proximity\").drop(columns=\"proximity\")\n", " return popular_cultures, sorted_df[[\"LIBELLE_CULTURE\",\"LIBELLE_GROUPE_CULTURE\",\"SURF_PARC\"]]\n", " popular_cultures = df[\"LIBELLE_CULTURE\"].value_counts().head(10).index\n", " df = df[df[\"LIBELLE_CULTURE\"].isin(popular_cultures)]\n", " return popular_cultures, df[[\"LIBELLE_CULTURE\",\"LIBELLE_GROUPE_CULTURE\",\"SURF_PARC\"]]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | LIBELLE_CULTURE | \n", "LIBELLE_GROUPE_CULTURE | \n", "SURF_PARC | \n", "
---|---|---|---|
26 | \n", "Autre plante fourragère annuelle (ni légumineu... | \n", "Fourrage | \n", "118.12 | \n", "
49 | \n", "Aïl | \n", "Légumes ou fleurs | \n", "49.67 | \n", "
61 | \n", "Plantes médicinales et à parfum non pérennes (... | \n", "Autres cultures industrielles | \n", "29.14 | \n", "
78 | \n", "Plante aromatique pérenne non arbustive ou arb... | \n", "Autres cultures industrielles | \n", "20.14 | \n", "
14 | \n", "Autre culture pérenne et jachère dans les bana... | \n", "Divers | \n", "5.31 | \n", "
37 | \n", "Agrume | \n", "Vergers | \n", "3.18 | \n", "
2 | \n", "Plantes aromatiques herbacées non pérennes (< ... | \n", "Autres cultures industrielles | \n", "277.71 | \n", "
117 | \n", "Avoine de printemps | \n", "Autres céréales | \n", "877.02 | \n", "
91 | \n", "Artichaut | \n", "Légumes ou fleurs | \n", "2953.38 | \n", "
104 | \n", "Avoine d’hiver | \n", "Autres céréales | \n", "5176.17 | \n", "