Complétion brouillon
This commit is contained in:
		
							parent
							
								
									0ffbe06b12
								
							
						
					
					
						commit
						be0bcda0ba
					
				|  | @ -10,7 +10,7 @@ | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "cell_type": "code", |    "cell_type": "code", | ||||||
|    "execution_count": 1, |    "execution_count": 22, | ||||||
|    "id": "b1a5b9d3", |    "id": "b1a5b9d3", | ||||||
|    "metadata": {}, |    "metadata": {}, | ||||||
|    "outputs": [], |    "outputs": [], | ||||||
|  | @ -20,7 +20,9 @@ | ||||||
|     "import os\n", |     "import os\n", | ||||||
|     "import s3fs\n", |     "import s3fs\n", | ||||||
|     "import re\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)" |     "        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", |    "cell_type": "markdown", | ||||||
|    "id": "ccf597b0-b459-4ea5-baf0-5ba8c90915e4", |    "id": "ccf597b0-b459-4ea5-baf0-5ba8c90915e4", | ||||||
|  | @ -599,7 +619,7 @@ | ||||||
|     "            'sport': ['5', '6', '7', '8', '9'],\n", |     "            'sport': ['5', '6', '7', '8', '9'],\n", | ||||||
|     "            'musique' : ['10', '11', '12', '13', '14']}\n", |     "            'musique' : ['10', '11', '12', '13', '14']}\n", | ||||||
|     "\n", |     "\n", | ||||||
|     "nb_compagnie = companies['sport']\n", |     "nb_compagnie = companies['mu']\n", | ||||||
|     "\n", |     "\n", | ||||||
|     "def load_files(nb_compagnie):\n", |     "def load_files(nb_compagnie):\n", | ||||||
|     "    targets = pd.DataFrame()\n", |     "    targets = pd.DataFrame()\n", | ||||||
|  | @ -632,13 +652,13 @@ | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "cell_type": "code", |    "cell_type": "code", | ||||||
|    "execution_count": 21, |    "execution_count": 27, | ||||||
|    "id": "3c911274-0ebd-49af-9487-26524ba20e74", |    "id": "3c911274-0ebd-49af-9487-26524ba20e74", | ||||||
|    "metadata": {}, |    "metadata": {}, | ||||||
|    "outputs": [], |    "outputs": [], | ||||||
|    "source": [ |    "source": [ | ||||||
|     "\n", |     "\n", | ||||||
|     "def target_description(targets):\n", |     "def target_description(targets, type_of_activity):\n", | ||||||
|     "\n", |     "\n", | ||||||
|     "    describe_target = targets.groupby('number_company').agg(\n", |     "    describe_target = targets.groupby('number_company').agg(\n", | ||||||
|     "        prop_target_jeune=('target_jeune', lambda x: (x.sum() / x.count())*100),\n", |     "        prop_target_jeune=('target_jeune', lambda x: (x.sum() / x.count())*100),\n", | ||||||
|  | @ -665,12 +685,13 @@ | ||||||
|     "    # Adding a legend\n", |     "    # Adding a legend\n", | ||||||
|     "    plot.legend([\"Youth\", \"School\", \"Enterprise\", \"Family\", \"Optin\", \"Optout\", \"Newsletter\", \"Subscriber\"], title=\"Target Category\")\n", |     "    plot.legend([\"Youth\", \"School\", \"Enterprise\", \"Family\", \"Optin\", \"Optout\", \"Newsletter\", \"Subscriber\"], title=\"Target Category\")\n", | ||||||
|     "\n", |     "\n", | ||||||
|  |     "    # save_file_s3(\"target_category_proportion_\", type_of_activity)\n", | ||||||
|     "    return plot" |     "    return plot" | ||||||
|    ] |    ] | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "cell_type": "code", |    "cell_type": "code", | ||||||
|    "execution_count": 22, |    "execution_count": 28, | ||||||
|    "id": "af62ecef-9120-4107-af3e-512588a96800", |    "id": "af62ecef-9120-4107-af3e-512588a96800", | ||||||
|    "metadata": {}, |    "metadata": {}, | ||||||
|    "outputs": [ |    "outputs": [ | ||||||
|  | @ -680,7 +701,7 @@ | ||||||
|        "<Axes: title={'center': 'Distribution of Targets by Category'}, xlabel='Company Number', ylabel='Target Proportion'>" |        "<Axes: title={'center': 'Distribution of Targets by Category'}, xlabel='Company Number', ylabel='Target Proportion'>" | ||||||
|       ] |       ] | ||||||
|      }, |      }, | ||||||
|      "execution_count": 22, |      "execution_count": 28, | ||||||
|      "metadata": {}, |      "metadata": {}, | ||||||
|      "output_type": "execute_result" |      "output_type": "execute_result" | ||||||
|     }, |     }, | ||||||
|  | @ -696,7 +717,7 @@ | ||||||
|     } |     } | ||||||
|    ], |    ], | ||||||
|    "source": [ |    "source": [ | ||||||
|     "target_description(targets)" |     "target_description(targets, 'sport')" | ||||||
|    ] |    ] | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user