{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ex3 - Getting and Knowing your Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This time we are going to pull data directly from the internet.\n", "Special thanks to: https://github.com/justmarkham for sharing the dataset and materials.\n", "\n", "### Step 1. Import the necessary libraries" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/justmarkham/DAT8/master/data/u.user). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3. Assign it to a variable called users and use the 'user_id' as index" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 4. See the first 25 entries" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": true }, "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", " \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", " \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", "
agegenderoccupationzip_code
user_id
124Mtechnician85711
253Fother94043
323Mwriter32067
424Mtechnician43537
533Fother15213
642Mexecutive98101
757Madministrator91344
836Madministrator05201
929Mstudent01002
1053Mlawyer90703
1139Fother30329
1228Fother06405
1347Meducator29206
1445Mscientist55106
1549Feducator97301
1621Mentertainment10309
1730Mprogrammer06355
1835Fother37212
1940Mlibrarian02138
2042Fhomemaker95660
2126Mwriter30068
2225Mwriter40206
2330Fartist48197
2421Fartist94533
2539Mengineer55107
\n", "
" ], "text/plain": [ " age gender occupation zip_code\n", "user_id \n", "1 24 M technician 85711\n", "2 53 F other 94043\n", "3 23 M writer 32067\n", "4 24 M technician 43537\n", "5 33 F other 15213\n", "6 42 M executive 98101\n", "7 57 M administrator 91344\n", "8 36 M administrator 05201\n", "9 29 M student 01002\n", "10 53 M lawyer 90703\n", "11 39 F other 30329\n", "12 28 F other 06405\n", "13 47 M educator 29206\n", "14 45 M scientist 55106\n", "15 49 F educator 97301\n", "16 21 M entertainment 10309\n", "17 30 M programmer 06355\n", "18 35 F other 37212\n", "19 40 M librarian 02138\n", "20 42 F homemaker 95660\n", "21 26 M writer 30068\n", "22 25 M writer 40206\n", "23 30 F artist 48197\n", "24 21 F artist 94533\n", "25 39 M engineer 55107" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 5. See the last 10 entries" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": true }, "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", " \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", "
agegenderoccupationzip_code
user_id
93461Mengineer22902
93542Mdoctor66221
93624Mother32789
93748Meducator98072
93838Ftechnician55038
93926Fstudent33319
94032Madministrator02215
94120Mstudent97229
94248Flibrarian78209
94322Mstudent77841
\n", "
" ], "text/plain": [ " age gender occupation zip_code\n", "user_id \n", "934 61 M engineer 22902\n", "935 42 M doctor 66221\n", "936 24 M other 32789\n", "937 48 M educator 98072\n", "938 38 F technician 55038\n", "939 26 F student 33319\n", "940 32 M administrator 02215\n", "941 20 M student 97229\n", "942 48 F librarian 78209\n", "943 22 M student 77841" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 6. What is the number of observations in the dataset?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "943" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 7. What is the number of columns in the dataset?" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 8. Print the name of all the columns." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Index([u'age', u'gender', u'occupation', u'zip_code'], dtype='object')" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 9. How is the dataset indexed?" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "Int64Index([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n", " ...\n", " 934, 935, 936, 937, 938, 939, 940, 941, 942, 943],\n", " dtype='int64', name=u'user_id', length=943)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 10. What is the data type of each column?" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "age int64\n", "gender object\n", "occupation object\n", "zip_code object\n", "dtype: object" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 11. Print only the occupation column" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "user_id\n", "1 technician\n", "2 other\n", "3 writer\n", "4 technician\n", "5 other\n", "6 executive\n", "7 administrator\n", "8 administrator\n", "9 student\n", "10 lawyer\n", "11 other\n", "12 other\n", "13 educator\n", "14 scientist\n", "15 educator\n", "16 entertainment\n", "17 programmer\n", "18 other\n", "19 librarian\n", "20 homemaker\n", "21 writer\n", "22 writer\n", "23 artist\n", "24 artist\n", "25 engineer\n", "26 engineer\n", "27 librarian\n", "28 writer\n", "29 programmer\n", "30 student\n", " ... \n", "914 other\n", "915 entertainment\n", "916 engineer\n", "917 student\n", "918 scientist\n", "919 other\n", "920 artist\n", "921 student\n", "922 administrator\n", "923 student\n", "924 other\n", "925 salesman\n", "926 entertainment\n", "927 programmer\n", "928 student\n", "929 scientist\n", "930 scientist\n", "931 educator\n", "932 educator\n", "933 student\n", "934 engineer\n", "935 doctor\n", "936 other\n", "937 educator\n", "938 technician\n", "939 student\n", "940 administrator\n", "941 student\n", "942 librarian\n", "943 student\n", "Name: occupation, dtype: object" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 12. How many different occupations there are in this dataset?" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "21" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 13. What is the most frequent occupation?" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "student 196\n", "other 105\n", "educator 95\n", "administrator 79\n", "engineer 67\n", "Name: occupation, dtype: int64" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 14. Summarize the DataFrame." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": 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", "
age
count943.000000
mean34.051962
std12.192740
min7.000000
25%25.000000
50%31.000000
75%43.000000
max73.000000
\n", "
" ], "text/plain": [ " age\n", "count 943.000000\n", "mean 34.051962\n", "std 12.192740\n", "min 7.000000\n", "25% 25.000000\n", "50% 31.000000\n", "75% 43.000000\n", "max 73.000000" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 15. Summarize all the columns" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "scrolled": true }, "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", " \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", "
agegenderoccupationzip_code
count943.000000943943943
uniqueNaN221795
topNaNMstudent55414
freqNaN6701969
mean34.051962NaNNaNNaN
std12.192740NaNNaNNaN
min7.000000NaNNaNNaN
25%25.000000NaNNaNNaN
50%31.000000NaNNaNNaN
75%43.000000NaNNaNNaN
max73.000000NaNNaNNaN
\n", "
" ], "text/plain": [ " age gender occupation zip_code\n", "count 943.000000 943 943 943\n", "unique NaN 2 21 795\n", "top NaN M student 55414\n", "freq NaN 670 196 9\n", "mean 34.051962 NaN NaN NaN\n", "std 12.192740 NaN NaN NaN\n", "min 7.000000 NaN NaN NaN\n", "25% 25.000000 NaN NaN NaN\n", "50% 31.000000 NaN NaN NaN\n", "75% 43.000000 NaN NaN NaN\n", "max 73.000000 NaN NaN NaN" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 16. Summarize only the occupation column" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "count 943\n", "unique 21\n", "top student\n", "freq 196\n", "Name: occupation, dtype: object" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 17. What is the mean age of users?" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "34.0" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 18. What is the age with least occurrence?" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "7 1\n", "Name: age, dtype: int64" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }