Skip to content

Commit

Permalink
ejercicio pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorillas committed Sep 3, 2023
1 parent 2194955 commit eb2c920
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions notebooks/pandas1_ejercicio.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analizar datos de ventas\n",
"\n",
"Crea un archivo CSV (`ventas.csv`) con la siguiente información:\n",
"\n",
"```csv\n",
"Fecha,Producto,Cantidad,Precio\n",
"2023-01-01,Manzana,10,2.5\n",
"2023-01-01,Pera,5,3\n",
"2023-01-02,Manzana,8,2.5\n",
"2023-01-02,Pera,2,3\n",
"2023-01-03,Manzana,12,2.5\n",
"```\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Usa Pandas responder a las preguntas\n",
"* ¿Cuál es el producto más vendido?\n",
"* ¿Cuánto ingreso se generó cada día?\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"# Leer datos desde un archivo CSV\n",
"df = pd.read_csv('ventas.csv')\n",
"\n",
"# Calcular el ingreso de cada venta\n",
"df['Ingreso'] = df['Cantidad'] * df['Precio']\n",
"\n",
"# Sumar el ingreso por cada producto\n",
"ingreso_producto = df.groupby('Producto')['Ingreso'].sum()\n",
"\n",
"# Sumar el ingreso por cada fecha\n",
"ingreso_fecha = df.groupby('Fecha')['Ingreso'].sum()\n",
"\n",
"print(f\"Ingreso por producto:\\n{ingreso_producto}\")\n",
"print(f\"Ingreso por fecha:\\n{ingreso_fecha}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "env",
"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.6.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit eb2c920

Please sign in to comment.