mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Updated markdown discussions for clarity and consistency.
This commit is contained in:
parent
e7ea21486d
commit
daa7665ef7
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:a3a2ee34a40ca6d18902bc7ba52393ce71aa5dda1937d48cdd0db3044dc235bf"
|
||||
"signature": "sha256:d9028f29469f49a645af74dd1ee28614caee8ca7ca47089925560fa874a2384b"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -39,7 +39,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Python treats functions as objects which can simplify data cleaning"
|
||||
"Python treats functions as objects which can simplify data cleaning. The following contains a transform utility class with two functions to clean strings:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -84,6 +84,13 @@
|
|||
],
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Below are nose tests that exercises the utility functions:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -132,6 +139,13 @@
|
|||
],
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Execute the nose tests in verbose mode:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -169,14 +183,14 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Lambda functions are anonymous function and are convenient for data analysis, as data transformation functions take functions as arguments."
|
||||
"Lambda functions are anonymous functions and are convenient for data analysis, as data transformation functions take functions as arguments."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Sort a sequence of strings by the number of letters"
|
||||
"Sort a sequence of strings by the number of letters:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -215,6 +229,13 @@
|
|||
"Closures are dynamically-genearated functions returned by another function. The returned function has access to the variables in the local namespace where it was created."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Each time the following closure() is called, it generates the same output:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
@ -244,7 +265,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The following function returns a function that keeps track of arguments it has seen."
|
||||
"Keep track of arguments passed:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -261,17 +282,8 @@
|
|||
" dict_seen[x] = True\n",
|
||||
" return False\n",
|
||||
" \n",
|
||||
" return watcher"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
" return watcher\n",
|
||||
"\n",
|
||||
"watcher = make_watcher()\n",
|
||||
"seq = [1, 1, 2, 3, 5, 8, 13, 2, 5, 13]\n",
|
||||
"[watcher(x) for x in seq]"
|
||||
|
@ -282,13 +294,13 @@
|
|||
{
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 7,
|
||||
"prompt_number": 6,
|
||||
"text": [
|
||||
"[False, True, False, False, False, False, False, True, True, True]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 7
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -301,7 +313,14 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\\*args and \\*\\*kwargs are useful when you don't know how many arguments might be passed to your function or to handle named arguments that you have not defined in advance."
|
||||
"\\*args and \\*\\*kwargs are useful when you don't know how many arguments might be passed to your function or when you want to handle named arguments that you have not defined in advance."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Print arguments and call the input function on *args:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -331,7 +350,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 8
|
||||
"prompt_number": 7
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user