{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 1\n", "Import NumPy under the alias `np`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 2\n", "Import pandas under the alias `pd`." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 3\n", "We will again be using salesperson data to test your knowledge of the `groupby` method. Given the dataset `data`, print a new DataFrame that shows the mean sales per salesperson, grouped by `Organization`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OrganizationSalesperson NameSales
0Coca-ColaNick200
1Coca-ColaJoel120
2PepsiTaylor125
3PepsiJosiah250
4Dr. PepperJosh150
5Dr. PepperMicaiah500
\n", "
" ], "text/plain": [ " Organization Salesperson Name Sales\n", "0 Coca-Cola Nick 200\n", "1 Coca-Cola Joel 120\n", "2 Pepsi Taylor 125\n", "3 Pepsi Josiah 250\n", "4 Dr. Pepper Josh 150\n", "5 Dr. Pepper Micaiah 500" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.DataFrame([ ['Coca-Cola', 'Nick', 200],\n", "\n", " ['Coca-Cola', 'Joel', 120],\n", "\n", " ['Pepsi','Taylor', 125],\n", "\n", " ['Pepsi','Josiah', 250],\n", "\n", " ['Dr. Pepper','Josh', 150],\n", "\n", " ['Dr. Pepper','Micaiah', 500]], \n", " columns = ['Organization', 'Salesperson Name', 'Sales'])\n", "\n", "data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sales
Organization
Coca-Cola160.0
Dr. Pepper325.0
Pepsi187.5
\n", "
" ], "text/plain": [ " Sales\n", "Organization \n", "Coca-Cola 160.0\n", "Dr. Pepper 325.0\n", "Pepsi 187.5" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Solution goes here\n", "data.groupby('Organization').mean()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 4\n", "Given the dataset `data`, print a new DataFrame that shows the total sales for each `Organization`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sales
Organization
Coca-Cola320
Dr. Pepper650
Pepsi375
\n", "
" ], "text/plain": [ " Sales\n", "Organization \n", "Coca-Cola 320\n", "Dr. Pepper 650\n", "Pepsi 375" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.groupby('Organization').sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 5\n", "Given the dataset data, print a new DataFrame that applies the describe method to each organization." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sales
countmeanstdmin25%50%75%max
Organization
Coca-Cola2.0160.056.568542120.0140.00160.0180.00200.0
Dr. Pepper2.0325.0247.487373150.0237.50325.0412.50500.0
Pepsi2.0187.588.388348125.0156.25187.5218.75250.0
\n", "
" ], "text/plain": [ " Sales \n", " count mean std min 25% 50% 75% max\n", "Organization \n", "Coca-Cola 2.0 160.0 56.568542 120.0 140.00 160.0 180.00 200.0\n", "Dr. Pepper 2.0 325.0 247.487373 150.0 237.50 325.0 412.50 500.0\n", "Pepsi 2.0 187.5 88.388348 125.0 156.25 187.5 218.75 250.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.groupby('Organization').describe()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }