PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/04_Apply/US_Crime_Rates/Exercises.ipynb

https://gitlab.com/santosh.sivapurapu-ab/pandas_exercises
Jupyter | 179 lines | 179 code | 0 blank | 0 comment | 0 complexity | 4158636fa29bee59f09493bc730fa2db MD5 | raw file
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# United States - Crime Rates - 1960 - 2014"
  8. ]
  9. },
  10. {
  11. "cell_type": "markdown",
  12. "metadata": {},
  13. "source": [
  14. "### Introduction:\n",
  15. "\n",
  16. "This time you will create a data \n",
  17. "\n",
  18. "Special thanks to: https://github.com/justmarkham for sharing the dataset and materials.\n",
  19. "\n",
  20. "### Step 1. Import the necessary libraries"
  21. ]
  22. },
  23. {
  24. "cell_type": "code",
  25. "execution_count": null,
  26. "metadata": {
  27. "collapsed": false
  28. },
  29. "outputs": [],
  30. "source": []
  31. },
  32. {
  33. "cell_type": "markdown",
  34. "metadata": {},
  35. "source": [
  36. "### Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/04_Apply/US_Crime_Rates/US_Crime_Rates_1960_2014.csv). "
  37. ]
  38. },
  39. {
  40. "cell_type": "markdown",
  41. "metadata": {},
  42. "source": [
  43. "### Step 3. Assign it to a variable called crime."
  44. ]
  45. },
  46. {
  47. "cell_type": "code",
  48. "execution_count": null,
  49. "metadata": {
  50. "collapsed": false
  51. },
  52. "outputs": [],
  53. "source": []
  54. },
  55. {
  56. "cell_type": "markdown",
  57. "metadata": {},
  58. "source": [
  59. "### Step 4. What is the type of the columns?"
  60. ]
  61. },
  62. {
  63. "cell_type": "code",
  64. "execution_count": null,
  65. "metadata": {
  66. "collapsed": false
  67. },
  68. "outputs": [],
  69. "source": []
  70. },
  71. {
  72. "cell_type": "markdown",
  73. "metadata": {},
  74. "source": [
  75. "##### Have you noticed that the type of Year is int64. But pandas has a different type to work with Time Series. Let's see it now.\n",
  76. "\n",
  77. "### Step 5. Convert the type of the column Year to datetime64"
  78. ]
  79. },
  80. {
  81. "cell_type": "code",
  82. "execution_count": null,
  83. "metadata": {
  84. "collapsed": false
  85. },
  86. "outputs": [],
  87. "source": []
  88. },
  89. {
  90. "cell_type": "markdown",
  91. "metadata": {},
  92. "source": [
  93. "### Step 6. Set the Year column as the index of the dataframe"
  94. ]
  95. },
  96. {
  97. "cell_type": "code",
  98. "execution_count": null,
  99. "metadata": {
  100. "collapsed": false
  101. },
  102. "outputs": [],
  103. "source": []
  104. },
  105. {
  106. "cell_type": "markdown",
  107. "metadata": {},
  108. "source": [
  109. "### Step 7. Delete the Total column"
  110. ]
  111. },
  112. {
  113. "cell_type": "code",
  114. "execution_count": null,
  115. "metadata": {
  116. "collapsed": false
  117. },
  118. "outputs": [],
  119. "source": []
  120. },
  121. {
  122. "cell_type": "markdown",
  123. "metadata": {},
  124. "source": [
  125. "### Step 8. Group the year by decades and sum the values\n",
  126. "\n",
  127. "#### Pay attention to the Population column number, summing this column is a mistake"
  128. ]
  129. },
  130. {
  131. "cell_type": "code",
  132. "execution_count": null,
  133. "metadata": {
  134. "collapsed": false,
  135. "scrolled": true
  136. },
  137. "outputs": [],
  138. "source": []
  139. },
  140. {
  141. "cell_type": "markdown",
  142. "metadata": {},
  143. "source": [
  144. "### Step 9. What is the mos dangerous decade to live in the US?"
  145. ]
  146. },
  147. {
  148. "cell_type": "code",
  149. "execution_count": null,
  150. "metadata": {
  151. "collapsed": false
  152. },
  153. "outputs": [],
  154. "source": []
  155. }
  156. ],
  157. "metadata": {
  158. "anaconda-cloud": {},
  159. "kernelspec": {
  160. "display_name": "Python [default]",
  161. "language": "python",
  162. "name": "python2"
  163. },
  164. "language_info": {
  165. "codemirror_mode": {
  166. "name": "ipython",
  167. "version": 2
  168. },
  169. "file_extension": ".py",
  170. "mimetype": "text/x-python",
  171. "name": "python",
  172. "nbconvert_exporter": "python",
  173. "pygments_lexer": "ipython2",
  174. "version": "2.7.12"
  175. }
  176. },
  177. "nbformat": 4,
  178. "nbformat_minor": 0
  179. }