Skip to content

Commit c9b27a9

Browse files
committed
Excluded wrong questions
1 parent 55a338e commit c9b27a9

File tree

3 files changed

+17
-171
lines changed

3 files changed

+17
-171
lines changed

04_Apply/US_Crime_Rates/Exercises.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@
155155
}
156156
],
157157
"metadata": {
158+
"anaconda-cloud": {},
158159
"kernelspec": {
159-
"display_name": "Python 2",
160+
"display_name": "Python [default]",
160161
"language": "python",
161162
"name": "python2"
162163
},
@@ -170,7 +171,7 @@
170171
"name": "python",
171172
"nbconvert_exporter": "python",
172173
"pygments_lexer": "ipython2",
173-
"version": "2.7.11"
174+
"version": "2.7.12"
174175
}
175176
},
176177
"nbformat": 4,

04_Apply/US_Crime_Rates/Exercises_with_solutions.ipynb

Lines changed: 12 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,18 @@
719719
}
720720
],
721721
"source": [
722-
"# select the first two columns from the origional dataset\n",
722+
"# To learn more about .resample (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html)\n",
723+
"# To learn more about Offset Aliases (http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases)\n",
724+
"\n",
725+
"# Uses resample to sum each decade\n",
723726
"crimes = crime.resample('10AS').sum()\n",
727+
"\n",
728+
"# Uses resample to get the max value only for the \"Population\" column\n",
724729
"population = crime['Population'].resample('10AS').max()\n",
730+
"\n",
731+
"# Updating the \"Population\" column\n",
725732
"crimes['Population'] = population\n",
733+
"\n",
726734
"crimes"
727735
]
728736
},
@@ -765,143 +773,12 @@
765773
"# apparently the 90s was a pretty dangerous time in the US\n",
766774
"crime.idxmax(0)"
767775
]
768-
},
769-
{
770-
"cell_type": "markdown",
771-
"metadata": {},
772-
"source": [
773-
"### Step 10. Find out which Year over Year delta was "
774-
]
775-
},
776-
{
777-
"cell_type": "code",
778-
"execution_count": null,
779-
"metadata": {
780-
"collapsed": false
781-
},
782-
"outputs": [],
783-
"source": []
784-
},
785-
{
786-
"cell_type": "markdown",
787-
"metadata": {},
788-
"source": [
789-
"### Step 11. How many items were orderd in total?"
790-
]
791-
},
792-
{
793-
"cell_type": "code",
794-
"execution_count": 279,
795-
"metadata": {
796-
"collapsed": false
797-
},
798-
"outputs": [
799-
{
800-
"ename": "AttributeError",
801-
"evalue": "'int' object has no attribute 'max'",
802-
"output_type": "error",
803-
"traceback": [
804-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
805-
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
806-
"\u001b[0;32m<ipython-input-279-dc545c79125f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mcrime\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Violent'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;31m# crime.apply(f, axis=1)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
807-
"\u001b[0;32m//anaconda/lib/python2.7/site-packages/pandas/core/series.pyc\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, func, convert_dtype, args, **kwds)\u001b[0m\n\u001b[1;32m 2218\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2219\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masobject\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2220\u001b[0;31m \u001b[0mmapped\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_infer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconvert\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconvert_dtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2221\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2222\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmapped\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmapped\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSeries\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
808-
"\u001b[0;32mpandas/src/inference.pyx\u001b[0m in \u001b[0;36mpandas.lib.map_infer (pandas/lib.c:62658)\u001b[0;34m()\u001b[0m\n",
809-
"\u001b[0;32m<ipython-input-279-dc545c79125f>\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(x)\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmin\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 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mcrime\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Violent'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# crime.apply(f, axis=1)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
810-
"\u001b[0;31mAttributeError\u001b[0m: 'int' object has no attribute 'max'"
811-
]
812-
}
813-
],
814-
"source": [
815-
"f = lambda x: x.max() - x.min()\n",
816-
"\n",
817-
"crime['Violent'].apply(f)\n",
818-
"# crime.apply(f, axis=1)"
819-
]
820-
},
821-
{
822-
"cell_type": "markdown",
823-
"metadata": {},
824-
"source": [
825-
"### Step 12. How many orders have more than 1 item?"
826-
]
827-
},
828-
{
829-
"cell_type": "code",
830-
"execution_count": null,
831-
"metadata": {
832-
"collapsed": false
833-
},
834-
"outputs": [],
835-
"source": []
836-
},
837-
{
838-
"cell_type": "markdown",
839-
"metadata": {},
840-
"source": [
841-
"### Step 13. How much was the revenue for the period in the dataset?"
842-
]
843-
},
844-
{
845-
"cell_type": "code",
846-
"execution_count": null,
847-
"metadata": {
848-
"collapsed": false
849-
},
850-
"outputs": [],
851-
"source": []
852-
},
853-
{
854-
"cell_type": "markdown",
855-
"metadata": {},
856-
"source": [
857-
"### Step 14. How many orders were made in the period?"
858-
]
859-
},
860-
{
861-
"cell_type": "code",
862-
"execution_count": null,
863-
"metadata": {
864-
"collapsed": true
865-
},
866-
"outputs": [],
867-
"source": []
868-
},
869-
{
870-
"cell_type": "markdown",
871-
"metadata": {},
872-
"source": [
873-
"### Step 15. What is the average amount per order?"
874-
]
875-
},
876-
{
877-
"cell_type": "code",
878-
"execution_count": null,
879-
"metadata": {
880-
"collapsed": true
881-
},
882-
"outputs": [],
883-
"source": []
884-
},
885-
{
886-
"cell_type": "markdown",
887-
"metadata": {},
888-
"source": [
889-
"### Step 16. How many different items are sold?"
890-
]
891-
},
892-
{
893-
"cell_type": "code",
894-
"execution_count": null,
895-
"metadata": {
896-
"collapsed": true
897-
},
898-
"outputs": [],
899-
"source": []
900776
}
901777
],
902778
"metadata": {
779+
"anaconda-cloud": {},
903780
"kernelspec": {
904-
"display_name": "Python 2",
781+
"display_name": "Python [default]",
905782
"language": "python",
906783
"name": "python2"
907784
},
@@ -915,7 +792,7 @@
915792
"name": "python",
916793
"nbconvert_exporter": "python",
917794
"pygments_lexer": "ipython2",
918-
"version": "2.7.11"
795+
"version": "2.7.12"
919796
}
920797
},
921798
"nbformat": 4,

04_Apply/US_Crime_Rates/Solutions.ipynb

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -737,43 +737,11 @@
737737
}
738738
],
739739
"source": []
740-
},
741-
{
742-
"cell_type": "markdown",
743-
"metadata": {},
744-
"source": [
745-
"### Step 10. Find out which Year over Year delta was "
746-
]
747-
},
748-
{
749-
"cell_type": "code",
750-
"execution_count": null,
751-
"metadata": {
752-
"collapsed": false
753-
},
754-
"outputs": [],
755-
"source": []
756-
},
757-
{
758-
"cell_type": "markdown",
759-
"metadata": {},
760-
"source": [
761-
"### Step 11. How many items were orderd in total?"
762-
]
763-
},
764-
{
765-
"cell_type": "code",
766-
"execution_count": null,
767-
"metadata": {
768-
"collapsed": false
769-
},
770-
"outputs": [],
771-
"source": []
772740
}
773741
],
774742
"metadata": {
775743
"kernelspec": {
776-
"display_name": "Python 2",
744+
"display_name": "Python [default]",
777745
"language": "python",
778746
"name": "python2"
779747
},
@@ -787,7 +755,7 @@
787755
"name": "python",
788756
"nbconvert_exporter": "python",
789757
"pygments_lexer": "ipython2",
790-
"version": "2.7.11"
758+
"version": "2.7.12"
791759
}
792760
},
793761
"nbformat": 4,

0 commit comments

Comments
 (0)