From b2058459b42606ab70c0309c318ec9922c4ba55e Mon Sep 17 00:00:00 2001 From: Anish Date: Mon, 20 Jan 2020 23:14:20 +1100 Subject: [PATCH] finished implementing functions, almost complete functionality of habits data. still have to make it pretty --- notebook.ipynb | 175 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 15 deletions(-) diff --git a/notebook.ipynb b/notebook.ipynb index 6dcb8f1..7cd3fcc 100644 --- a/notebook.ipynb +++ b/notebook.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 183, "metadata": {}, "outputs": [ { @@ -71,16 +71,157 @@ ] }, { - "ename": "NameError", - "evalue": "name 'index' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Longest streak: \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlongestStreak\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Longest zeros: \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlongestZero\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Best month: \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mcalendar\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmonth_name\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msumMonth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0midxmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0;31m#print(\"Worst month: \" + calendar.month_name[int(sumMonth(df).idxmin())])\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;31m#plotScore(df)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m\u001b[0m in \u001b[0;36msumMonth\u001b[0;34m(df)\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msumMonth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 43\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'month'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDatetimeIndex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmonth\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 44\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroupby\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'month'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'index' is not defined" - ] + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
MeditateExerciseReadJournaldevlogPlantsDraw
month
40.1333330.2666670.0000000.9000000.0000001.1333330.000000
50.3870970.1935480.1935480.6451610.0000000.5161290.000000
60.5000000.2666670.1666670.6666670.0000000.0000000.000000
70.5161290.8387100.9677420.7741940.0645160.6129030.000000
80.8064520.7419350.9354841.1612901.2258061.1935480.000000
91.1333330.6000001.2333331.3000001.0666671.3333330.000000
100.7741941.0645160.5806450.9354841.0322581.1935480.000000
110.7000000.7333330.8000001.2333331.0000000.3333330.533333
120.3870970.5483871.0967740.7096770.6129030.0000000.612903
\n", + "
" + ], + "text/plain": [ + " Meditate Exercise Read Journal devlog Plants Draw\n", + "month \n", + "4 0.133333 0.266667 0.000000 0.900000 0.000000 1.133333 0.000000\n", + "5 0.387097 0.193548 0.193548 0.645161 0.000000 0.516129 0.000000\n", + "6 0.500000 0.266667 0.166667 0.666667 0.000000 0.000000 0.000000\n", + "7 0.516129 0.838710 0.967742 0.774194 0.064516 0.612903 0.000000\n", + "8 0.806452 0.741935 0.935484 1.161290 1.225806 1.193548 0.000000\n", + "9 1.133333 0.600000 1.233333 1.300000 1.066667 1.333333 0.000000\n", + "10 0.774194 1.064516 0.580645 0.935484 1.032258 1.193548 0.000000\n", + "11 0.700000 0.733333 0.800000 1.233333 1.000000 0.333333 0.533333\n", + "12 0.387097 0.548387 1.096774 0.709677 0.612903 0.000000 0.612903" + ] + }, + "execution_count": 183, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -94,14 +235,16 @@ "print(\"Streak days: \" + str(countValue(1, df)))\n", "print(\"Longest streak: \" + str(df.apply(longestStreak, axis=0)))\n", "print(\"Longest zeros: \" + str(df.apply(longestZero, axis=0)))\n", - "print(\"Best month: \" + calendar.month_name[int(sumMonth(df).idxmax())])\n", + "#print(\"Best month: \" + str(sumMonth(df)))\n", + "sumMonth(df)\n", + "meanMonth(df)\n", "#print(\"Worst month: \" + calendar.month_name[int(sumMonth(df).idxmin())])\n", "#plotScore(df)" ] }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 182, "metadata": {}, "outputs": [], "source": [ @@ -147,11 +290,13 @@ " return max(streakList)\n", "\n", "def sumMonth(df):\n", - " df['month'] = pd.DatetimeIndex(df[index]).month\n", + " df2 = df.reset_index()\n", + " df['month'] = pd.DatetimeIndex(df2['date']).month\n", " return df.groupby(['month']).sum()\n", "\n", "def meanMonth(df):\n", - " df['month'] = pd.DatetimeIndex(df['date']).month\n", + " df2 = df.reset_index()\n", + " df['month'] = pd.DatetimeIndex(df2['date']).month\n", " return df.groupby(['month']).mean()\n", "\n", "def plotScore(df):\n",