From be0bcda0baf410bbd4dcb7230719e6f0dedfcd8d Mon Sep 17 00:00:00 2001 From: ajoubrel-ensae Date: Wed, 27 Mar 2024 18:55:11 +0000 Subject: [PATCH] =?UTF-8?q?Compl=C3=A9tion=20brouillon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Exploration_billet_AJ.ipynb | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/Exploration_billet_AJ.ipynb b/Exploration_billet_AJ.ipynb index 886aaae..93995f5 100644 --- a/Exploration_billet_AJ.ipynb +++ b/Exploration_billet_AJ.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 22, "id": "b1a5b9d3", "metadata": {}, "outputs": [], @@ -20,7 +20,9 @@ "import os\n", "import s3fs\n", "import re\n", - "import warnings" + "import warnings\n", + "import io\n", + "import matplotlib.pyplot as plt\n" ] }, { @@ -97,6 +99,24 @@ " df.to_csv(file_out, index = False)" ] }, + { + "cell_type": "code", + "execution_count": 15, + "id": "108fc5ef-c56a-4f03-a867-943d9d6492fd", + "metadata": {}, + "outputs": [], + "source": [ + "def save_file_s3(File_name, type_of_activity):\n", + " image_buffer = io.BytesIO()\n", + " plt.savefig(image_buffer, format='png')\n", + " image_buffer.seek(0)\n", + " FILE_PATH = f\"projet-bdc2324-team1/stat_desc/{type_of_activity}/\"\n", + " FILE_PATH_OUT_S3 = FILE_PATH + File_name + type_of_activity + '.png'\n", + " with fs.open(FILE_PATH_OUT_S3, 'wb') as s3_file:\n", + " s3_file.write(image_buffer.read())\n", + " plt.close()" + ] + }, { "cell_type": "markdown", "id": "ccf597b0-b459-4ea5-baf0-5ba8c90915e4", @@ -599,7 +619,7 @@ " 'sport': ['5', '6', '7', '8', '9'],\n", " 'musique' : ['10', '11', '12', '13', '14']}\n", "\n", - "nb_compagnie = companies['sport']\n", + "nb_compagnie = companies['mu']\n", "\n", "def load_files(nb_compagnie):\n", " targets = pd.DataFrame()\n", @@ -632,13 +652,13 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 27, "id": "3c911274-0ebd-49af-9487-26524ba20e74", "metadata": {}, "outputs": [], "source": [ "\n", - "def target_description(targets):\n", + "def target_description(targets, type_of_activity):\n", "\n", " describe_target = targets.groupby('number_company').agg(\n", " prop_target_jeune=('target_jeune', lambda x: (x.sum() / x.count())*100),\n", @@ -665,12 +685,13 @@ " # Adding a legend\n", " plot.legend([\"Youth\", \"School\", \"Enterprise\", \"Family\", \"Optin\", \"Optout\", \"Newsletter\", \"Subscriber\"], title=\"Target Category\")\n", "\n", + " # save_file_s3(\"target_category_proportion_\", type_of_activity)\n", " return plot" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 28, "id": "af62ecef-9120-4107-af3e-512588a96800", "metadata": {}, "outputs": [ @@ -680,7 +701,7 @@ "" ] }, - "execution_count": 22, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" }, @@ -696,7 +717,7 @@ } ], "source": [ - "target_description(targets)" + "target_description(targets, 'sport')" ] }, {