From fbbc4f277e4975104e7a364a7c23d35f9026b538 Mon Sep 17 00:00:00 2001 From: devfzn Date: Sun, 30 Jun 2024 13:37:46 -0400 Subject: [PATCH] =?UTF-8?q?=20(-=20=CA=96=CC=AF-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ejercicio_01-checkpoint.ipynb | 6 + ctrl_2/ej_01/ejercicio_01.ipynb | 243 ++++++++++++++++++ ctrl_2/ej_01/test_00.py | 18 ++ ctrl_2/ej_01/venta_verduras_y_frutas.csv | 214 +++++++++++++++ 4 files changed, 481 insertions(+) create mode 100644 ctrl_2/ej_01/.ipynb_checkpoints/ejercicio_01-checkpoint.ipynb create mode 100644 ctrl_2/ej_01/ejercicio_01.ipynb create mode 100644 ctrl_2/ej_01/test_00.py create mode 100644 ctrl_2/ej_01/venta_verduras_y_frutas.csv diff --git a/ctrl_2/ej_01/.ipynb_checkpoints/ejercicio_01-checkpoint.ipynb b/ctrl_2/ej_01/.ipynb_checkpoints/ejercicio_01-checkpoint.ipynb new file mode 100644 index 0000000..363fcab --- /dev/null +++ b/ctrl_2/ej_01/.ipynb_checkpoints/ejercicio_01-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ctrl_2/ej_01/ejercicio_01.ipynb b/ctrl_2/ej_01/ejercicio_01.ipynb new file mode 100644 index 0000000..7b8c6dc --- /dev/null +++ b/ctrl_2/ej_01/ejercicio_01.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "22f35792-a38d-49bf-8e02-c299271055cb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Order_ID Product Category Amount Date Country\n", + "count 213.000000 213 213 213 213 213\n", + "unique NaN 7 2 213 150 7\n", + "top NaN Banana Fruit $4'270 16-01-16 United States\n", + "freq NaN 71 146 1 4 57\n", + "mean 107.000000 NaN NaN NaN NaN NaN\n", + "std 61.631972 NaN NaN NaN NaN NaN\n", + "min 1.000000 NaN NaN NaN NaN NaN\n", + "25% 54.000000 NaN NaN NaN NaN NaN\n", + "50% 107.000000 NaN NaN NaN NaN NaN\n", + "75% 160.000000 NaN NaN NaN NaN NaN\n", + "max 213.000000 NaN NaN NaN NaN NaN\n" + ] + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "df = pd.read_csv('venta_verduras_y_frutas.csv')\n", + "\n", + "print(df.describe(include='all'))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ec8937dc-0605-4dcc-9f7c-faeac54c05d9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Order_ID Product Category Amount Date Country\n", + "0 1 Carrots Vegetables $4'270 06-01-16 United States\n", + "1 2 Broccoli Vegetables $8'239 07-01-16 United Kingdom\n", + "2 3 Banana Fruit $617 08-01-16 United States\n", + "3 4 Banana Fruit $8'384 10-01-16 Canada\n", + "4 5 Beans Vegetables $2'626 10-01-16 Germany\n", + "5 6 Orange Fruit $3'610 11-01-16 United States\n", + "6 7 Broccoli Vegetables $9'062 11-01-16 Australia\n", + "7 8 Banana Fruit $6'906 16-01-16 New Zealand\n", + "8 9 Apple Fruit $2'417 16-01-16 France\n", + "9 10 Apple Fruit $7'431 16-01-16 Canada\n" + ] + } + ], + "source": [ + "print(df.head(10))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "598245c7-d0c7-4173-aaf8-e7511d4b10a9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Order_ID Product Category Amount Date Country\n", + "203 204 Orange Fruit $2'782 20-12-16 United Kingdom\n", + "204 205 Apple Fruit $2'455 20-12-16 Canada\n", + "205 206 Apple Fruit $4'512 22-12-16 New Zealand\n", + "206 207 Apple Fruit $8'752 22-12-16 Germany\n", + "207 208 Carrots Vegetables $9'127 25-12-16 United States\n", + "208 209 Apple Fruit $1'777 28-12-16 France\n", + "209 210 Beans Vegetables $680 28-12-16 France\n", + "210 211 Orange Fruit $958 29-12-16 United States\n", + "211 212 Carrots Vegetables $2'613 29-12-16 Australia\n", + "212 213 Carrots Vegetables $339 30-12-16 Australia\n" + ] + } + ], + "source": [ + "print(df.tail(10))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "64be6624-d703-4ade-9eb6-c55f9e379250", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Category Amount\n", + "0 Vegetables $4'270\n", + "1 Vegetables $8'239\n", + "2 Fruit $617\n", + "3 Fruit $8'384\n", + "4 Vegetables $2'626\n", + ".. ... ...\n", + "208 Fruit $1'777\n", + "209 Vegetables $680\n", + "210 Fruit $958\n", + "211 Vegetables $2'613\n", + "212 Vegetables $339\n", + "\n", + "[213 rows x 2 columns]\n" + ] + } + ], + "source": [ + "parcial_data = df[['Category','Amount']]\n", + "print(parcial_data)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "1511d979-3831-4f84-ac77-73d0f0958497", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['Order_ID', 'Product', 'Category', 'Amount', 'Date', 'Country'], dtype='object')\n" + ] + } + ], + "source": [ + "columnas = df.columns\n", + "print(columnas)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "6a97d112-05f8-44f2-8ca9-0bded4b73283", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Order_ID Product Category Amount Date Country\n", + "2 3 Banana Fruit $617 08-01-16 United States\n", + "3 4 Banana Fruit $8'384 10-01-16 Canada\n", + "5 6 Orange Fruit $3'610 11-01-16 United States\n", + "7 8 Banana Fruit $6'906 16-01-16 New Zealand\n", + "8 9 Apple Fruit $2'417 16-01-16 France\n", + ".. ... ... ... ... ... ...\n", + "204 205 Apple Fruit $2'455 20-12-16 Canada\n", + "205 206 Apple Fruit $4'512 22-12-16 New Zealand\n", + "206 207 Apple Fruit $8'752 22-12-16 Germany\n", + "208 209 Apple Fruit $1'777 28-12-16 France\n", + "210 211 Orange Fruit $958 29-12-16 United States\n", + "\n", + "[146 rows x 6 columns]\n" + ] + } + ], + "source": [ + "frutas = df[df['Category']=='Fruit']\n", + "print(frutas)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "e49afb79-1749-421a-bd63-919bc1c74bcf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Order_ID \n", + " count mean std min 25% 50% 75% max\n", + "Category \n", + "Fruit 146.0 107.239726 60.488734 3.0 56.75 106.0 158.75 211.0\n", + "Vegetables 67.0 106.477612 64.516467 1.0 47.50 110.0 161.50 213.0\n" + ] + } + ], + "source": [ + "grupos = df.groupby('Category')\n", + "print(grupos.describe())" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "afe9d318-f0f9-4214-8935-9f6c6214f5e8", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'inspect' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[20], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#frutas = df.filter()\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m help(\u001b[43minspect\u001b[49m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'inspect' is not defined" + ] + } + ], + "source": [ + "#frutas = df.filter()\n", + "help(inspect)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.12.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ctrl_2/ej_01/test_00.py b/ctrl_2/ej_01/test_00.py new file mode 100644 index 0000000..ff8eea2 --- /dev/null +++ b/ctrl_2/ej_01/test_00.py @@ -0,0 +1,18 @@ +import pandas as pd +# import numpy as np + +df = pd.read_csv('./venta_verduras_y_frutas.csv') + +print(df.describe(include='all')) + +print(df.head(10)) +print(type(df)) + +frutas = df[df['Category'] == 'Fruit'] +categorias = df.groupby(['Category']) + +print(frutas) +print(type(frutas)) + +pt = df.pivot(columns='Category') +print(pt) diff --git a/ctrl_2/ej_01/venta_verduras_y_frutas.csv b/ctrl_2/ej_01/venta_verduras_y_frutas.csv new file mode 100644 index 0000000..ccbd96c --- /dev/null +++ b/ctrl_2/ej_01/venta_verduras_y_frutas.csv @@ -0,0 +1,214 @@ +Order_ID,Product,Category,Amount,Date,Country +1,Carrots,Vegetables,$4'270,06-01-16,United States +2,Broccoli,Vegetables,$8'239,07-01-16,United Kingdom +3,Banana,Fruit,$617,08-01-16,United States +4,Banana,Fruit,$8'384,10-01-16,Canada +5,Beans,Vegetables,$2'626,10-01-16,Germany +6,Orange,Fruit,$3'610,11-01-16,United States +7,Broccoli,Vegetables,$9'062,11-01-16,Australia +8,Banana,Fruit,$6'906,16-01-16,New Zealand +9,Apple,Fruit,$2'417,16-01-16,France +10,Apple,Fruit,$7'431,16-01-16,Canada +11,Banana,Fruit,$8'250,16-01-16,Germany +12,Broccoli,Vegetables,$7'012,18-01-16,United States +13,Carrots,Vegetables,$1'903,20-01-16,Germany +14,Broccoli,Vegetables,$2'824,22-01-16,Canada +15,Apple,Fruit,$6'946,24-01-16,France +16,Banana,Fruit,$2'320,27-01-16,United Kingdom +17,Banana,Fruit,$2'116,28-01-16,United States +18,Banana,Fruit,$1'135,30-01-16,United Kingdom +19,Broccoli,Vegetables,$3'595,30-01-16,United Kingdom +20,Apple,Fruit,$1'161,02-02-16,United States +21,Orange,Fruit,$2'256,04-02-16,France +22,Banana,Fruit,$1'004,11-02-16,New Zealand +23,Banana,Fruit,$3'642,14-02-16,Canada +24,Banana,Fruit,$4'582,17-02-16,United States +25,Beans,Vegetables,$3'559,17-02-16,United Kingdom +26,Carrots,Vegetables,$5'154,17-02-16,Australia +27,Mango,Fruit,$7'388,18-02-16,France +28,Beans,Vegetables,$7'163,18-02-16,United States +29,Beans,Vegetables,$5'101,20-02-16,Germany +30,Apple,Fruit,$7'602,21-02-16,France +31,Mango,Fruit,$1'641,22-02-16,United States +32,Apple,Fruit,$8'892,23-02-16,Australia +33,Apple,Fruit,$2'060,29-02-16,France +34,Broccoli,Vegetables,$1'557,29-02-16,Germany +35,Apple,Fruit,$6'509,01-03-16,France +36,Apple,Fruit,$5'718,04-03-16,Australia +37,Apple,Fruit,$7'655,05-03-16,United States +38,Carrots,Vegetables,$9'116,05-03-16,United Kingdom +39,Banana,Fruit,$2'795,15-03-16,United States +40,Banana,Fruit,$5'084,15-03-16,United States +41,Carrots,Vegetables,$8'941,15-03-16,United Kingdom +42,Broccoli,Vegetables,$5'341,16-03-16,France +43,Banana,Fruit,$135,19-03-16,Canada +44,Banana,Fruit,$9'400,19-03-16,Australia +45,Beans,Vegetables,$6'045,21-03-16,Germany +46,Apple,Fruit,$5'820,22-03-16,New Zealand +47,Orange,Fruit,$8'887,23-03-16,Germany +48,Orange,Fruit,$6'982,24-03-16,United States +49,Banana,Fruit,$4'029,26-03-16,Australia +50,Carrots,Vegetables,$3'665,26-03-16,Germany +51,Banana,Fruit,$4'781,29-03-16,France +52,Mango,Fruit,$3'663,30-03-16,Australia +53,Apple,Fruit,$6'331,01-04-16,France +54,Apple,Fruit,$4'364,01-04-16,Canada +55,Carrots,Vegetables,$607,03-04-16,United Kingdom +56,Banana,Fruit,$1'054,06-04-16,New Zealand +57,Carrots,Vegetables,$7'659,06-04-16,United States +58,Broccoli,Vegetables,$277,12-04-16,Germany +59,Banana,Fruit,$235,17-04-16,United States +60,Orange,Fruit,$1'113,18-04-16,Australia +61,Apple,Fruit,$1'128,21-04-16,United States +62,Broccoli,Vegetables,$9'231,22-04-16,Canada +63,Banana,Fruit,$4'387,23-04-16,United States +64,Apple,Fruit,$2'763,25-04-16,Canada +65,Banana,Fruit,$7'898,27-04-16,United Kingdom +66,Banana,Fruit,$2'427,30-04-16,France +67,Banana,Fruit,$8'663,01-05-16,New Zealand +68,Carrots,Vegetables,$2'789,01-05-16,Germany +69,Banana,Fruit,$4'054,02-05-16,United States +70,Mango,Fruit,$2'262,02-05-16,United States +71,Mango,Fruit,$5'600,02-05-16,United Kingdom +72,Banana,Fruit,$5'787,03-05-16,United States +73,Orange,Fruit,$6'295,03-05-16,Canada +74,Banana,Fruit,$474,05-05-16,Germany +75,Apple,Fruit,$4'325,05-05-16,France +76,Banana,Fruit,$592,06-05-16,United States +77,Orange,Fruit,$4'330,08-05-16,United States +78,Banana,Fruit,$9'405,08-05-16,United Kingdom +79,Apple,Fruit,$7'671,08-05-16,France +80,Carrots,Vegetables,$5'791,08-05-16,United Kingdom +81,Banana,Fruit,$6'007,12-05-16,Canada +82,Banana,Fruit,$5'030,14-05-16,Germany +83,Carrots,Vegetables,$6'763,14-05-16,United Kingdom +84,Banana,Fruit,$4'248,15-05-16,Australia +85,Banana,Fruit,$9'543,16-05-16,France +86,Broccoli,Vegetables,$2'054,16-05-16,United Kingdom +87,Beans,Vegetables,$7'094,16-05-16,Germany +88,Carrots,Vegetables,$6'087,18-05-16,United States +89,Apple,Fruit,$4'264,19-05-16,Australia +90,Mango,Fruit,$9'333,20-05-16,United States +91,Mango,Fruit,$8'775,22-05-16,Germany +92,Broccoli,Vegetables,$2'011,23-05-16,United Kingdom +93,Banana,Fruit,$5'632,25-05-16,United States +94,Banana,Fruit,$4'904,25-05-16,New Zealand +95,Beans,Vegetables,$1'002,25-05-16,Australia +96,Orange,Fruit,$8'141,26-05-16,United Kingdom +97,Orange,Fruit,$3'644,26-05-16,Canada +98,Orange,Fruit,$1'380,26-05-16,Australia +99,Broccoli,Vegetables,$8'354,26-05-16,Germany +100,Banana,Fruit,$5'182,27-05-16,United States +101,Apple,Fruit,$2'193,27-05-16,France +102,Mango,Fruit,$3'647,28-05-16,United States +103,Apple,Fruit,$4'104,28-05-16,United States +104,Carrots,Vegetables,$7'457,28-05-16,United States +105,Mango,Fruit,$3'767,29-05-16,Canada +106,Broccoli,Vegetables,$4'685,30-05-16,Germany +107,Banana,Fruit,$3'917,04-06-16,United States +108,Apple,Fruit,$521,04-06-16,Canada +109,Apple,Fruit,$5'605,10-06-16,France +110,Broccoli,Vegetables,$9'630,11-06-16,Germany +111,Banana,Fruit,$6'941,20-06-16,Canada +112,Broccoli,Vegetables,$7'231,20-06-16,United Kingdom +113,Broccoli,Vegetables,$8'891,23-06-16,Australia +114,Banana,Fruit,$107,25-06-16,France +115,Banana,Fruit,$4'243,26-06-16,United States +116,Orange,Fruit,$4'514,27-06-16,United States +117,Mango,Fruit,$5'480,02-07-16,United States +118,Banana,Fruit,$5'002,02-07-16,France +119,Banana,Fruit,$8'530,05-07-16,Canada +120,Orange,Fruit,$4'819,07-07-16,New Zealand +121,Broccoli,Vegetables,$6'343,11-07-16,United Kingdom +122,Orange,Fruit,$2'318,13-07-16,United Kingdom +123,Orange,Fruit,$220,20-07-16,United Kingdom +124,Orange,Fruit,$6'341,20-07-16,New Zealand +125,Apple,Fruit,$330,20-07-16,Germany +126,Broccoli,Vegetables,$3'027,20-07-16,United Kingdom +127,Orange,Fruit,$850,22-07-16,New Zealand +128,Banana,Fruit,$8'986,23-07-16,United Kingdom +129,Broccoli,Vegetables,$3'800,25-07-16,United States +130,Carrots,Vegetables,$5'751,28-07-16,United Kingdom +131,Apple,Fruit,$1'704,29-07-16,United Kingdom +132,Banana,Fruit,$7'966,30-07-16,Australia +133,Banana,Fruit,$852,31-07-16,United States +134,Beans,Vegetables,$8'416,31-07-16,Australia +135,Banana,Fruit,$7'144,01-08-16,France +136,Broccoli,Vegetables,$7'854,01-08-16,United States +137,Orange,Fruit,$859,03-08-16,United States +138,Broccoli,Vegetables,$8'049,12-08-16,United States +139,Banana,Fruit,$2'836,13-08-16,Germany +140,Carrots,Vegetables,$1'743,19-08-16,United States +141,Apple,Fruit,$3'844,23-08-16,France +142,Apple,Fruit,$7'490,24-08-16,France +143,Broccoli,Vegetables,$4'483,25-08-16,Germany +144,Apple,Fruit,$7'333,27-08-16,Canada +145,Carrots,Vegetables,$7'654,28-08-16,United States +146,Apple,Fruit,$3'944,29-08-16,United Kingdom +147,Beans,Vegetables,$5'761,29-08-16,Germany +148,Banana,Fruit,$6'864,01-09-16,New Zealand +149,Banana,Fruit,$4'016,01-09-16,Germany +150,Banana,Fruit,$1'841,02-09-16,United States +151,Banana,Fruit,$424,05-09-16,Australia +152,Banana,Fruit,$8'765,07-09-16,United Kingdom +153,Banana,Fruit,$5'583,08-09-16,United States +154,Broccoli,Vegetables,$4'390,09-09-16,New Zealand +155,Broccoli,Vegetables,$352,09-09-16,Canada +156,Apple,Fruit,$8'489,11-09-16,United States +157,Banana,Fruit,$7'090,11-09-16,France +158,Banana,Fruit,$7'880,15-09-16,United States +159,Orange,Fruit,$3'861,18-09-16,United States +160,Broccoli,Vegetables,$7'927,19-09-16,Germany +161,Banana,Fruit,$6'162,20-09-16,United States +162,Mango,Fruit,$5'523,25-09-16,Australia +163,Broccoli,Vegetables,$5'936,25-09-16,United Kingdom +164,Carrots,Vegetables,$7'251,26-09-16,Germany +165,Orange,Fruit,$6'187,27-09-16,Australia +166,Banana,Fruit,$3'210,29-09-16,Germany +167,Carrots,Vegetables,$682,29-09-16,Germany +168,Banana,Fruit,$793,03-10-16,Australia +169,Carrots,Vegetables,$5'346,04-10-16,Germany +170,Banana,Fruit,$7'103,07-10-16,New Zealand +171,Carrots,Vegetables,$4'603,10-10-16,United States +172,Apple,Fruit,$8'160,16-10-16,France +173,Apple,Fruit,$7'171,23-10-16,United Kingdom +174,Banana,Fruit,$3'552,23-10-16,New Zealand +175,Banana,Fruit,$7'273,25-10-16,Australia +176,Banana,Fruit,$2'402,26-10-16,Germany +177,Banana,Fruit,$1'197,26-10-16,Australia +178,Beans,Vegetables,$5'015,26-10-16,Australia +179,Orange,Fruit,$5'818,02-11-16,United States +180,Banana,Fruit,$4'399,03-11-16,United Kingdom +181,Carrots,Vegetables,$3'011,03-11-16,United States +182,Apple,Fruit,$4'715,09-11-16,United Kingdom +183,Apple,Fruit,$5'321,12-11-16,France +184,Banana,Fruit,$8'894,15-11-16,United States +185,Carrots,Vegetables,$4'846,25-11-16,United Kingdom +186,Broccoli,Vegetables,$284,25-11-16,Germany +187,Orange,Fruit,$8'283,26-11-16,United Kingdom +188,Orange,Fruit,$9'990,28-11-16,Canada +189,Banana,Fruit,$9'014,28-11-16,Australia +190,Apple,Fruit,$1'942,29-11-16,France +191,Banana,Fruit,$7'223,30-11-16,United States +192,Carrots,Vegetables,$4'673,02-12-16,United States +193,Carrots,Vegetables,$9'104,04-12-16,France +194,Apple,Fruit,$6'078,05-12-16,United States +195,Beans,Vegetables,$3'278,06-12-16,Germany +196,Banana,Fruit,$136,12-12-16,Canada +197,Banana,Fruit,$8'377,12-12-16,Australia +198,Banana,Fruit,$2'382,12-12-16,United States +199,Banana,Fruit,$8'702,15-12-16,Germany +200,Banana,Fruit,$5'021,16-12-16,United States +201,Apple,Fruit,$1'760,16-12-16,Australia +202,Banana,Fruit,$4'766,18-12-16,Germany +203,Beans,Vegetables,$1'541,19-12-16,United Kingdom +204,Orange,Fruit,$2'782,20-12-16,United Kingdom +205,Apple,Fruit,$2'455,20-12-16,Canada +206,Apple,Fruit,$4'512,22-12-16,New Zealand +207,Apple,Fruit,$8'752,22-12-16,Germany +208,Carrots,Vegetables,$9'127,25-12-16,United States +209,Apple,Fruit,$1'777,28-12-16,France +210,Beans,Vegetables,$680,28-12-16,France +211,Orange,Fruit,$958,29-12-16,United States +212,Carrots,Vegetables,$2'613,29-12-16,Australia +213,Carrots,Vegetables,$339,30-12-16,Australia \ No newline at end of file