Skip to content

Commit 5686095

Browse files
committed
updated examples
1 parent a86dede commit 5686095

File tree

7 files changed

+129
-194
lines changed

7 files changed

+129
-194
lines changed

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
# Python Snippets
22

3-
These __Python Snippets__ are tested with Python 3.5.x. All snippets are
3+
These __Python Snippets__ are tested with Python 3.6.x. All snippets are
44
available as Jupyter notebooks (http://jupyter.org/).
55

66

77
## Get started...
88
To get started create a virtual environment and install the required packages.
99

10-
### Virtualenv
11-
The following example shows how to create an environment with
12-
_"virtualenv"_ (https://virtualenv.pypa.io/)
13-
and Python 3.5 with the required packages.
10+
- Juypter Notebook
11+
- pandas
12+
- geojson
13+
- beautifulsoup4
14+
- feedparser
15+
- scikit-image
16+
- matplotlib
1417

15-
```bash
16-
virtualenv --python=/usr/bin/python3.5 py35-ps
17-
18-
source py35-ps/bin/activate
19-
20-
pip install -r requirements.txt
21-
```
2218

2319
### Conda
2420
The following example shows how to create an environment with _"conda"_
25-
(http://conda.pydata.org/) and Python 3.5 with
21+
(http://conda.pydata.org/) and Python 3.6 with
2622
the required packages.
2723

2824
```bash
29-
conda create -n py35-ps python=3.5
25+
conda create -n py36-ps python=3.6
3026

31-
source activate py35-ps
27+
source activate py36-ps
3228

33-
pip install -r requirements.txt
3429
```
3530

3631
## The Python Snippets
@@ -47,4 +42,4 @@ __HTTP__
4742
- [Extract the text from a HTML document with Beautiful Soup](http/beautifulsoup4.ipynb)
4843

4944
__Image__
50-
- tbd
45+
- [Image diff with scikit-image](image/image_diff.ipynb)

geojson/geojson_stations.ipynb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,26 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 1,
46-
"metadata": {
47-
"collapsed": false
48-
},
45+
"execution_count": 2,
46+
"metadata": {},
4947
"outputs": [
5048
{
5149
"data": {
5250
"text/html": [
5351
"<div>\n",
52+
"<style scoped>\n",
53+
" .dataframe tbody tr th:only-of-type {\n",
54+
" vertical-align: middle;\n",
55+
" }\n",
56+
"\n",
57+
" .dataframe tbody tr th {\n",
58+
" vertical-align: top;\n",
59+
" }\n",
60+
"\n",
61+
" .dataframe thead th {\n",
62+
" text-align: right;\n",
63+
" }\n",
64+
"</style>\n",
5465
"<table border=\"1\" class=\"dataframe\">\n",
5566
" <thead>\n",
5667
" <tr style=\"text-align: right;\">\n",
@@ -116,7 +127,7 @@
116127
"4 22.0 7.589551 47.547405 277.0 Basel SBB"
117128
]
118129
},
119-
"execution_count": 1,
130+
"execution_count": 2,
120131
"metadata": {},
121132
"output_type": "execute_result"
122133
}
@@ -137,9 +148,8 @@
137148
},
138149
{
139150
"cell_type": "code",
140-
"execution_count": 2,
151+
"execution_count": 3,
141152
"metadata": {
142-
"collapsed": false,
143153
"scrolled": true
144154
},
145155
"outputs": [],
@@ -161,10 +171,8 @@
161171
},
162172
{
163173
"cell_type": "code",
164-
"execution_count": 3,
165-
"metadata": {
166-
"collapsed": false
167-
},
174+
"execution_count": 4,
175+
"metadata": {},
168176
"outputs": [
169177
{
170178
"name": "stdout",
@@ -195,18 +203,16 @@
195203
},
196204
{
197205
"cell_type": "code",
198-
"execution_count": 4,
199-
"metadata": {
200-
"collapsed": false
201-
},
206+
"execution_count": 5,
207+
"metadata": {},
202208
"outputs": [
203209
{
204210
"data": {
205211
"text/plain": [
206212
"\"\\nwith open('stations.geojson', 'w') as file:\\n file.write(dump)\\n\""
207213
]
208214
},
209-
"execution_count": 4,
215+
"execution_count": 5,
210216
"metadata": {},
211217
"output_type": "execute_result"
212218
}
@@ -232,9 +238,7 @@
232238
{
233239
"cell_type": "code",
234240
"execution_count": null,
235-
"metadata": {
236-
"collapsed": true
237-
},
241+
"metadata": {},
238242
"outputs": [],
239243
"source": []
240244
}
@@ -255,7 +259,7 @@
255259
"name": "python",
256260
"nbconvert_exporter": "python",
257261
"pygments_lexer": "ipython3",
258-
"version": "3.5.2"
262+
"version": "3.6.7"
259263
}
260264
},
261265
"nbformat": 4,

http/beautifulsoup4.ipynb

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": null,
15-
"metadata": {
16-
"collapsed": true
17-
},
14+
"execution_count": 1,
15+
"metadata": {},
1816
"outputs": [],
1917
"source": [
2018
"html_doc = \"\"\"\n",
@@ -41,10 +39,8 @@
4139
},
4240
{
4341
"cell_type": "code",
44-
"execution_count": null,
45-
"metadata": {
46-
"collapsed": false
47-
},
42+
"execution_count": 2,
43+
"metadata": {},
4844
"outputs": [],
4945
"source": [
5046
"from bs4 import BeautifulSoup\n",
@@ -80,18 +76,16 @@
8076
},
8177
{
8278
"cell_type": "code",
83-
"execution_count": 13,
84-
"metadata": {
85-
"collapsed": false
86-
},
79+
"execution_count": 3,
80+
"metadata": {},
8781
"outputs": [
8882
{
8983
"data": {
9084
"text/plain": [
9185
"'My new page'"
9286
]
9387
},
94-
"execution_count": 13,
88+
"execution_count": 3,
9589
"metadata": {},
9690
"output_type": "execute_result"
9791
}
@@ -109,10 +103,8 @@
109103
},
110104
{
111105
"cell_type": "code",
112-
"execution_count": 14,
113-
"metadata": {
114-
"collapsed": false
115-
},
106+
"execution_count": 4,
107+
"metadata": {},
116108
"outputs": [
117109
{
118110
"name": "stdout",
@@ -138,18 +130,16 @@
138130
},
139131
{
140132
"cell_type": "code",
141-
"execution_count": 15,
142-
"metadata": {
143-
"collapsed": false
144-
},
133+
"execution_count": 5,
134+
"metadata": {},
145135
"outputs": [
146136
{
147137
"data": {
148138
"text/plain": [
149139
"'\\nMy new page\\n\\nCool my new page\\nI have written the following articles:\\nA1,\\nA2\\nA3;\\n\\n...\\n'"
150140
]
151141
},
152-
"execution_count": 15,
142+
"execution_count": 5,
153143
"metadata": {},
154144
"output_type": "execute_result"
155145
}
@@ -175,7 +165,7 @@
175165
"name": "python",
176166
"nbconvert_exporter": "python",
177167
"pygments_lexer": "ipython3",
178-
"version": "3.5.2"
168+
"version": "3.6.7"
179169
}
180170
},
181171
"nbformat": 4,

http/urlib.ipynb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 21,
15-
"metadata": {
16-
"collapsed": false
17-
},
14+
"execution_count": 1,
15+
"metadata": {},
1816
"outputs": [],
1917
"source": [
2018
"import urllib.request"
@@ -30,10 +28,8 @@
3028
},
3129
{
3230
"cell_type": "code",
33-
"execution_count": 22,
34-
"metadata": {
35-
"collapsed": false
36-
},
31+
"execution_count": 2,
32+
"metadata": {},
3733
"outputs": [],
3834
"source": [
3935
"url = 'https://medium.com/tag/machine-learning'\n",
@@ -50,10 +46,8 @@
5046
},
5147
{
5248
"cell_type": "code",
53-
"execution_count": 23,
54-
"metadata": {
55-
"collapsed": false
56-
},
49+
"execution_count": 3,
50+
"metadata": {},
5751
"outputs": [
5852
{
5953
"name": "stdout",
@@ -76,18 +70,16 @@
7670
},
7771
{
7872
"cell_type": "code",
79-
"execution_count": 24,
80-
"metadata": {
81-
"collapsed": false
82-
},
73+
"execution_count": 4,
74+
"metadata": {},
8375
"outputs": [
8476
{
8577
"data": {
8678
"text/plain": [
8779
"'text/html; charset=utf-8'"
8880
]
8981
},
90-
"execution_count": 24,
82+
"execution_count": 4,
9183
"metadata": {},
9284
"output_type": "execute_result"
9385
}
@@ -105,18 +97,16 @@
10597
},
10698
{
10799
"cell_type": "code",
108-
"execution_count": 25,
109-
"metadata": {
110-
"collapsed": false
111-
},
100+
"execution_count": 5,
101+
"metadata": {},
112102
"outputs": [
113103
{
114104
"data": {
115105
"text/plain": [
116-
"b'<!DOCTYPE html><html xmlns:cc=\"http://creativecommons.org/ns#\"><head prefix=\"og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# medium-com: http://ogp.me/ns/fb/medium-com#\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Machine Learning \\xe2\\x80\\x93 Medium</title><link rel=\"canonical\" href=\"https://medium.com/tag/machine-learning\"><link id=\"feedLink\" rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"/fee'"
106+
"b'<!DOCTYPE html><html xmlns:cc=\"http://creativecommons.org/ns#\"><head prefix=\"og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# medium-com: http://ogp.me/ns/fb/medium-com#\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, viewport-fit=contain\"><title>The most insightful stories about Machine Learning \\xe2\\x80\\x93 Medium</title><link rel=\"canonical\" href=\"https://medium.com/tag/machine-learning\"><link id=\"feedLink\" rel=\"al'"
117107
]
118108
},
119-
"execution_count": 25,
109+
"execution_count": 5,
120110
"metadata": {},
121111
"output_type": "execute_result"
122112
}
@@ -125,6 +115,13 @@
125115
"text = con.read()\n",
126116
"text[:500]"
127117
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": []
128125
}
129126
],
130127
"metadata": {
@@ -143,7 +140,7 @@
143140
"name": "python",
144141
"nbconvert_exporter": "python",
145142
"pygments_lexer": "ipython3",
146-
"version": "3.5.2"
143+
"version": "3.6.7"
147144
}
148145
},
149146
"nbformat": 4,

0 commit comments

Comments
 (0)