File size: 11,942 Bytes
7a4e6e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ae7d3d
7a4e6e5
 
 
 
 
 
 
 
 
1ae7d3d
7a4e6e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "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": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"./data_rpg/data_prepared_rpg.csv\")\n",
    "\n",
    "pop, sorted_df = get_popular_agriculture(\n",
    "    df,\n",
    "    \"Bretagne\",\n",
    "    132.5\n",
    "    \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LIBELLE_CULTURE</th>\n",
       "      <th>LIBELLE_GROUPE_CULTURE</th>\n",
       "      <th>SURF_PARC</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Autre plante fourragère annuelle (ni légumineu...</td>\n",
       "      <td>Fourrage</td>\n",
       "      <td>118.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>Aïl</td>\n",
       "      <td>Légumes ou fleurs</td>\n",
       "      <td>49.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>Plantes médicinales et à parfum non pérennes (...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>29.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>Plante aromatique pérenne non arbustive ou arb...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>20.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Autre culture pérenne et jachère dans les bana...</td>\n",
       "      <td>Divers</td>\n",
       "      <td>5.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>Agrume</td>\n",
       "      <td>Vergers</td>\n",
       "      <td>3.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Plantes aromatiques herbacées non pérennes (&lt; ...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>277.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>Avoine de printemps</td>\n",
       "      <td>Autres céréales</td>\n",
       "      <td>877.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>Artichaut</td>\n",
       "      <td>Légumes ou fleurs</td>\n",
       "      <td>2953.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>Avoine d’hiver</td>\n",
       "      <td>Autres céréales</td>\n",
       "      <td>5176.17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       LIBELLE_CULTURE  \\\n",
       "26   Autre plante fourragère annuelle (ni légumineu...   \n",
       "49                                                 Aïl   \n",
       "61   Plantes médicinales et à parfum non pérennes (...   \n",
       "78   Plante aromatique pérenne non arbustive ou arb...   \n",
       "14   Autre culture pérenne et jachère dans les bana...   \n",
       "37                                              Agrume   \n",
       "2    Plantes aromatiques herbacées non pérennes (< ...   \n",
       "117                                Avoine de printemps   \n",
       "91                                           Artichaut   \n",
       "104                                     Avoine d’hiver   \n",
       "\n",
       "            LIBELLE_GROUPE_CULTURE  SURF_PARC  \n",
       "26                        Fourrage     118.12  \n",
       "49               Légumes ou fleurs      49.67  \n",
       "61   Autres cultures industrielles      29.14  \n",
       "78   Autres cultures industrielles      20.14  \n",
       "14                          Divers       5.31  \n",
       "37                         Vergers       3.18  \n",
       "2    Autres cultures industrielles     277.71  \n",
       "117                Autres céréales     877.02  \n",
       "91               Légumes ou fleurs    2953.38  \n",
       "104                Autres céréales    5176.17  "
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LIBELLE_CULTURE</th>\n",
       "      <th>LIBELLE_GROUPE_CULTURE</th>\n",
       "      <th>SURF_PARC</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Plantes aromatiques herbacées non pérennes (&lt; ...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>277.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Autre culture pérenne et jachère dans les bana...</td>\n",
       "      <td>Divers</td>\n",
       "      <td>5.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Autre plante fourragère annuelle (ni légumineu...</td>\n",
       "      <td>Fourrage</td>\n",
       "      <td>118.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>Agrume</td>\n",
       "      <td>Vergers</td>\n",
       "      <td>3.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>Aïl</td>\n",
       "      <td>Légumes ou fleurs</td>\n",
       "      <td>49.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>Plantes médicinales et à parfum non pérennes (...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>29.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>Plante aromatique pérenne non arbustive ou arb...</td>\n",
       "      <td>Autres cultures industrielles</td>\n",
       "      <td>20.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>Artichaut</td>\n",
       "      <td>Légumes ou fleurs</td>\n",
       "      <td>2953.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>Avoine d’hiver</td>\n",
       "      <td>Autres céréales</td>\n",
       "      <td>5176.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>Avoine de printemps</td>\n",
       "      <td>Autres céréales</td>\n",
       "      <td>877.02</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       LIBELLE_CULTURE  \\\n",
       "2    Plantes aromatiques herbacées non pérennes (< ...   \n",
       "14   Autre culture pérenne et jachère dans les bana...   \n",
       "26   Autre plante fourragère annuelle (ni légumineu...   \n",
       "37                                              Agrume   \n",
       "49                                                 Aïl   \n",
       "61   Plantes médicinales et à parfum non pérennes (...   \n",
       "78   Plante aromatique pérenne non arbustive ou arb...   \n",
       "91                                           Artichaut   \n",
       "104                                     Avoine d’hiver   \n",
       "117                                Avoine de printemps   \n",
       "\n",
       "            LIBELLE_GROUPE_CULTURE  SURF_PARC  \n",
       "2    Autres cultures industrielles     277.71  \n",
       "14                          Divers       5.31  \n",
       "26                        Fourrage     118.12  \n",
       "37                         Vergers       3.18  \n",
       "49               Légumes ou fleurs      49.67  \n",
       "61   Autres cultures industrielles      29.14  \n",
       "78   Autres cultures industrielles      20.14  \n",
       "91               Légumes ou fleurs    2953.38  \n",
       "104                Autres céréales    5176.17  \n",
       "117                Autres céréales     877.02  "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted_df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "hackathon",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}