{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"MonthlyProductSales.csv\", encoding = \"ISO-8859-1\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 2013\n", "1 2015\n", "2 2013\n", "3 2016\n", "4 2016\n", " ... \n", "9247 2016\n", "9248 2016\n", "9249 2013\n", "9250 2016\n", "9251 2013\n", "Name: Month of Order Date, Length: 9252, dtype: object" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['Month of Order Date'].str[:4]" ] }, { "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", " \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
Month of Order Date
20131875.0258.267200803.5373741.017.055.0224.0022638.0
20141968.0239.107215521.3302891.019.062.0225.257312.0
20152400.0253.550833711.7950401.019.058.5222.0017500.0
20163009.0243.940512627.7415470.018.060.0221.0014000.0
\n", "
" ], "text/plain": [ " Sales \\\n", " count mean std min 25% 50% 75% \n", "Month of Order Date \n", "2013 1875.0 258.267200 803.537374 1.0 17.0 55.0 224.00 \n", "2014 1968.0 239.107215 521.330289 1.0 19.0 62.0 225.25 \n", "2015 2400.0 253.550833 711.795040 1.0 19.0 58.5 222.00 \n", "2016 3009.0 243.940512 627.741547 0.0 18.0 60.0 221.00 \n", "\n", " \n", " max \n", "Month of Order Date \n", "2013 22638.0 \n", "2014 7312.0 \n", "2015 17500.0 \n", "2016 14000.0 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby(df['Month of Order Date'].str[:4]).describe()" ] }, { "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", " \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", "
YearSales
countmeanstdmin25%50%75%max
020131875.0258.267200803.5373741.017.055.0224.0022638.0
120141968.0239.107215521.3302891.019.062.0225.257312.0
220152400.0253.550833711.7950401.019.058.5222.0017500.0
320163009.0243.940512627.7415470.018.060.0221.0014000.0
\n", "
" ], "text/plain": [ " Year Sales \n", " count mean std min 25% 50% 75% max\n", "0 2013 1875.0 258.267200 803.537374 1.0 17.0 55.0 224.00 22638.0\n", "1 2014 1968.0 239.107215 521.330289 1.0 19.0 62.0 225.25 7312.0\n", "2 2015 2400.0 253.550833 711.795040 1.0 19.0 58.5 222.00 17500.0\n", "3 2016 3009.0 243.940512 627.741547 0.0 18.0 60.0 221.00 14000.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby(df['Month of Order Date'].str[:4]).describe().reset_index().rename(columns={\"Month of Order Date\":\"Year\"})" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "yearly_product_sales = df.groupby([df[\"Month of Order Date\"].str[:4], \"Product Name\"]).sum(numeric_only = True).reset_index()" ] }, { "cell_type": "code", "execution_count": 8, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
YearProduct NameSales
02013#10 White Business Envelopes,4 1/8 x 9 1/2156.0
12013#10- 4 1/8\" x 9 1/2\" Recycled Envelopes63.0
22013#10- 4 1/8\" x 9 1/2\" Security-Tint Envelopes23.0
320131.7 Cubic Foot Compact \"Cube\" Office Refrigera...541.0
420131/4 Fold Party Design Invitations & White Enve...6.0
............
53212016iKross Bluetooth Portable Keyboard + Cell Phon...67.0
53222016iOttie HLCRIO102 Car Mount120.0
53232016iOttie XL Car Mount224.0
53242016invisibleSHIELD by ZAGG Smudge-Free Screen Pro...205.0
53252016netTALK DUO VoIP Telephone Service168.0
\n", "

5326 rows × 3 columns

\n", "
" ], "text/plain": [ " Year Product Name Sales\n", "0 2013 #10 White Business Envelopes,4 1/8 x 9 1/2 156.0\n", "1 2013 #10- 4 1/8\" x 9 1/2\" Recycled Envelopes 63.0\n", "2 2013 #10- 4 1/8\" x 9 1/2\" Security-Tint Envelopes 23.0\n", "3 2013 1.7 Cubic Foot Compact \"Cube\" Office Refrigera... 541.0\n", "4 2013 1/4 Fold Party Design Invitations & White Enve... 6.0\n", "... ... ... ...\n", "5321 2016 iKross Bluetooth Portable Keyboard + Cell Phon... 67.0\n", "5322 2016 iOttie HLCRIO102 Car Mount 120.0\n", "5323 2016 iOttie XL Car Mount 224.0\n", "5324 2016 invisibleSHIELD by ZAGG Smudge-Free Screen Pro... 205.0\n", "5325 2016 netTALK DUO VoIP Telephone Service 168.0\n", "\n", "[5326 rows x 3 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yearly_product_sales.rename(columns={\"Month of Order Date\":\"Year\"})" ] }, { "cell_type": "code", "execution_count": 10, "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", " \n", "
Product NameSales
0\"While you Were Out\" Message Book, One Form pe...25.0
1#10 Gummed Flap White Envelopes, 100/Box42.0
2#10 Self-Seal White Envelopes109.0
3#10 White Business Envelopes,4 1/8 x 9 1/2489.0
4#10- 4 1/8\" x 9 1/2\" Recycled Envelopes286.0
.........
1845iKross Bluetooth Portable Keyboard + Cell Phon...479.0
1846iOttie HLCRIO102 Car Mount216.0
1847iOttie XL Car Mount224.0
1848invisibleSHIELD by ZAGG Smudge-Free Screen Pro...442.0
1849netTALK DUO VoIP Telephone Service1113.0
\n", "

1850 rows × 2 columns

\n", "
" ], "text/plain": [ " Product Name Sales\n", "0 \"While you Were Out\" Message Book, One Form pe... 25.0\n", "1 #10 Gummed Flap White Envelopes, 100/Box 42.0\n", "2 #10 Self-Seal White Envelopes 109.0\n", "3 #10 White Business Envelopes,4 1/8 x 9 1/2 489.0\n", "4 #10- 4 1/8\" x 9 1/2\" Recycled Envelopes 286.0\n", "... ... ...\n", "1845 iKross Bluetooth Portable Keyboard + Cell Phon... 479.0\n", "1846 iOttie HLCRIO102 Car Mount 216.0\n", "1847 iOttie XL Car Mount 224.0\n", "1848 invisibleSHIELD by ZAGG Smudge-Free Screen Pro... 442.0\n", "1849 netTALK DUO VoIP Telephone Service 1113.0\n", "\n", "[1850 rows x 2 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby(\"Product Name\").sum(numeric_only = True).reset_index()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.10.9" } }, "nbformat": 4, "nbformat_minor": 2 }