{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#Import data file\n", "finances_path = \"PyBank_Budget_Data.csv\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#Read in CSV file\n", "finances_df = pd.read_csv(finances_path, encoding=\"utf-8\")" ] }, { "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", "
DateProfit/Losses
0Jan-10867884
1Feb-10984655
2Mar-10322013
3Apr-10-69417
4May-10310503
\n", "
" ], "text/plain": [ " Date Profit/Losses\n", "0 Jan-10 867884\n", "1 Feb-10 984655\n", "2 Mar-10 322013\n", "3 Apr-10 -69417\n", "4 May-10 310503" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Test above statement\n", "finances_df.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "86" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Calculatet the total number of months included in the dataset\n", "Date_count = len(finances_df[\"Date\"].unique())\n", "Date_count" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "$ 38382578\n" ] } ], "source": [ "#Calculate the net total amount of \"Profit/Losses\" over the entire period\n", "Total = finances_df[\"Profit/Losses\"].sum()\n", "print (\"$\", Total)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": false }, "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", "
DateProfit/LossesDifference
0Jan-10867884NaN
1Feb-10984655116771.0
2Mar-10322013-662642.0
3Apr-10-69417-391430.0
4May-10310503379920.0
\n", "
" ], "text/plain": [ " Date Profit/Losses Difference\n", "0 Jan-10 867884 NaN\n", "1 Feb-10 984655 116771.0\n", "2 Mar-10 322013 -662642.0\n", "3 Apr-10 -69417 -391430.0\n", "4 May-10 310503 379920.0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Difference in profit or loss by row\n", "Difference = finances_df [\"Profit/Losses\"].diff(+1)\n", "#Add column \"Difference\" to dataframe\n", "finances_df[\"Difference\"] = Difference\n", "\n", "finances_df.head()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "$ -2315\n" ] } ], "source": [ "#Calculate average change\n", "Average_Change = finances_df[\"Difference\"].mean()\n", "Average_Change = round(int(Average_Change))\n", "print (\"$\", Average_Change)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "$ 1926159 Feb-12\n" ] } ], "source": [ "#The greatest increase in profits (date and amount) over the entire period\n", "Greatest_Increase = finances_df[\"Difference\"].max()\n", "Greatest_Increase = round(int(Greatest_Increase))\n", "print(\"$\", Greatest_Increase, finances_df.loc[finances_df[\"Difference\"]== 1926159, \"Date\"].values[0])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "$ -2196167 Sep-13\n" ] } ], "source": [ "#The greatest decrease in profits (date and amount) over the entire period\n", "Greatest_Decrease = finances_df[\"Difference\"].min()\n", "Greatest_Decrease = round(int(Greatest_Decrease))\n", "print(\"$\", Greatest_Decrease, finances_df.loc[finances_df[\"Difference\"]== -2196167, \"Date\"].values[0])" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Financial Analysis\n", "________________________________________________\n", "\n", "Total Months: 86\n", "Total: $38382578\n", "Average Change: $-2315\n", "Greatest Increase: $ 1926159 Month: Feb-12\n", "Greatest Decrease: $ -2196167 Month : Sep-13\n" ] } ], "source": [ "# Print results\n", "print(\"Financial Analysis\")\n", "print(\"________________________________________________\")\n", "print(\"\")\n", "print(f\"Total Months: {(Date_count)}\")\n", "print(f\"Total: ${(Total)}\")\n", "print(f\"Average Change: ${(Average_Change)}\")\n", "print(\"Greatest Increase: $\", Greatest_Increase, \"Month: \",finances_df.loc[finances_df[\"Difference\"]== 1926159, \"Date\"].values[0])\n", "print(\"Greatest Decrease: $\", Greatest_Decrease, \"Month : \",finances_df.loc[finances_df[\"Difference\"]== -2196167, \"Date\"].values[0])" ] } ], "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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }