finished implementing functions, almost complete functionality of habits data. still have to make it pretty
This commit is contained in:
parent
757a2697f3
commit
b2058459b4
175
notebook.ipynb
175
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<ipython-input-159-0fca2d01ba7c>\u001b[0m in \u001b[0;36m<module>\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<ipython-input-157-8d2f281b4755>\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": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>Meditate</th>\n",
|
||||
" <th>Exercise</th>\n",
|
||||
" <th>Read</th>\n",
|
||||
" <th>Journal</th>\n",
|
||||
" <th>devlog</th>\n",
|
||||
" <th>Plants</th>\n",
|
||||
" <th>Draw</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>month</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>0.133333</td>\n",
|
||||
" <td>0.266667</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>0.900000</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>1.133333</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td>0.387097</td>\n",
|
||||
" <td>0.193548</td>\n",
|
||||
" <td>0.193548</td>\n",
|
||||
" <td>0.645161</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>0.516129</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td>0.500000</td>\n",
|
||||
" <td>0.266667</td>\n",
|
||||
" <td>0.166667</td>\n",
|
||||
" <td>0.666667</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td>0.516129</td>\n",
|
||||
" <td>0.838710</td>\n",
|
||||
" <td>0.967742</td>\n",
|
||||
" <td>0.774194</td>\n",
|
||||
" <td>0.064516</td>\n",
|
||||
" <td>0.612903</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>8</th>\n",
|
||||
" <td>0.806452</td>\n",
|
||||
" <td>0.741935</td>\n",
|
||||
" <td>0.935484</td>\n",
|
||||
" <td>1.161290</td>\n",
|
||||
" <td>1.225806</td>\n",
|
||||
" <td>1.193548</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>9</th>\n",
|
||||
" <td>1.133333</td>\n",
|
||||
" <td>0.600000</td>\n",
|
||||
" <td>1.233333</td>\n",
|
||||
" <td>1.300000</td>\n",
|
||||
" <td>1.066667</td>\n",
|
||||
" <td>1.333333</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>10</th>\n",
|
||||
" <td>0.774194</td>\n",
|
||||
" <td>1.064516</td>\n",
|
||||
" <td>0.580645</td>\n",
|
||||
" <td>0.935484</td>\n",
|
||||
" <td>1.032258</td>\n",
|
||||
" <td>1.193548</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>11</th>\n",
|
||||
" <td>0.700000</td>\n",
|
||||
" <td>0.733333</td>\n",
|
||||
" <td>0.800000</td>\n",
|
||||
" <td>1.233333</td>\n",
|
||||
" <td>1.000000</td>\n",
|
||||
" <td>0.333333</td>\n",
|
||||
" <td>0.533333</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>12</th>\n",
|
||||
" <td>0.387097</td>\n",
|
||||
" <td>0.548387</td>\n",
|
||||
" <td>1.096774</td>\n",
|
||||
" <td>0.709677</td>\n",
|
||||
" <td>0.612903</td>\n",
|
||||
" <td>0.000000</td>\n",
|
||||
" <td>0.612903</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"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",
|
||||
|
|
Loading…
Reference in a new issue