get connected with python

Post on 20-Jul-2015

169 Views

Category:

Social Media

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

#GetConnected with

Jan Kroon Hogeschool Rotterdam

Workshop 1

–Steve Jobs

"Computers are like a bicycle for our minds."

https://www.youtube.com/watch?v=ob_GX50Za6c

Computer Programming• Programming: to build a machine that does your work

• Whenever you enter a search term in Google, you are programming Google to search for you …

• but if you need to think about AND and/or OR and "grouping of search terms" most people give up.

• A computer is a general purpose machine: a calculator, a word processor, a drawing machine, a search machine, a remember machine, an analytics machine, an information machine, a communications machine, a game machine, a navigation machine, a music machine, a video machine, a design machine …

• If you learn how to program you can build these (and many other) machines!

Programming LanguagesExpressive Power:

1 line of code in Python, Perl, R or Ruby

3 lines of code in C++, C# or Java

10 lines of code in C

50-100 lines of code in Machine Language or Assembler

Python 3.4.0

In this workshop you will learn to write Python One Liners!

Guido van Rossum Benevolent Dictator For Life

Object Oriëntation

'Edwin Jansen' is a 'Plumber'

'Edwin Jansen' has properties: • edwinJansen.phoneNumber

• edwinJansen.available

'Edwin Jansen' has skills to do things: • edwinJansen.fixTap()

• edwinJansen.repairRoof()

>>> import plumber and let a plumber do the work!

Object Class

Methods (verbs)

Properties (nouns)

Everything is an object!• Whole Numbers: int

• Broken numbers: float

• Text: str

• User Interface Elements: Windows, Buttons, Sliders, TextFields, ImageViews, MapViews.

• Containers: list, dict, tuple, …

Assignment 0

Install Python on your laptop (use Google to look for Python / IDLE download)

IDLE Integrated DeveLopment Environment

Programmer's Workbench

Console "Python chat"

Editor "Python email"

Run menu Run Module

Syntax Colour Code?

Happy Coding!

print("Hello World")

help()

help(print)

type("Hello World")

IDLE

dir()

Assignment 1

Write your first computer program, a classic:

>>> print("Hello World")

Assignment 2

Introduce yourself:

>>> myName = "…"

>>> print("Hello", myName)

New Object!

Assignment 3

Introduce your group:

>>> ourGroup = ["Komala Mazerant", …]

and say hello to everyone (except yourself!)

Iteration (Looping)

>>> for student in ourGroup:

print("Hello", student)

Condition (Skipping)

… == … means 'is equal to'

… != … means 'is not equal to'

>>> for student in ourGroup:

if student != myName:

print("Hello", student)

Assignment 4Find out the class of the objects you created:

>>> type(…)

find out their size (length)

>>> len(…)

and find out what you can do with these objects

>>> dir(…)

and if you want detailed information use

>>> help(…)

Dynamic TypingTry this:

>>> aNumber = 747

>>> aNumber + aNumber

>>> sameNumber = str(aNumber)

>>> sameNumber + sameNumber

>>> anotherNumber = int(sameNumber)

>>> anotherNumber + anotherNumber

What is going on here???

Juggle with typesMake a 'class list' object from a 'class string' object:

>>> aQuote = "Computers are like a bicycle for our minds"

>>> quoteWords = aQuote.split()

and turn the words back into a sentence"

>>> aSentence = ""

>>> for word in quoteWords:

aSentence = aSentence + " " + word

Assignment 5Copy the contents of theJungle in an object:

>>> theJungle = "…"

A. Is there a lion in the jungle?

B. Where do you encounter the first tiger?

C. How many trees in the jungle?

Selection (Slicing)

>>> aStudent = ourGroup[1]

>>> someStudents = ourGroup[2:5]

>>> lastStudent = ourGroup[-1]

Assignment 6

Find palindromes in 'words' list:

>>> words = […]

Big Data

Assignment 7Browse to: https://twitter.com/search-advanced

A. How many tweets today in Rotterdam?

B. Any tweets with tag #GetConnected?

C. What is last tweet from @BarackObama

D. More positive or more negative tweets last week about @BarackObama?

Analytics1. Collect Data

2. Clean Data

3. Wrangle, Merge, Aggregate

4. Visualize, Summarize Data

5. Interpret, Develop Insights

6. Act!

Collect Data>>> from urllib import request

>>> twitterHandle = request.urlopen("http://twitter.com")

>>> twitterData = twitterHandle.read()

>>> twitterText = str(twitterData)

>>> twitterText[0:500]

>>> len(twitterText)

Assignment 8Copy the contents of aBusinessCard and someBusinessCards in two objects:

>>> aBusinessCard = […]

>>> someBusinessCards = […]

A. How can you recognize a phone number or an email address in aBusinessCard

B. Print a list of names extracted from someBusinessCards

C. Print a list of email addresses extracted from someBusinessCards

Assignment 9Copy the contents of tweets in an object:

>>> tweets = […]

A. How many tweets?

B. How many from Rotterdam?

C. Who has sent tweets with hashtag #GetConnected?

Assignment 10Copy the contents of twitterFollowers in an object:

>>> tf = "…"

A. Is there overlap in the followers of @KomalaDubois and @jankroon?

B. What would be the possibilities if you would know all followers of all people on Twitter?

Algorithms• Dictionary attack to break password protection

• Harvesting email addresses for spamming

• Recommendations: "People who rented this movie also rented …"

• Segmentation: clustering people that are similar in some respect

• Outlier detection: discover exceptional behavior, i.e. to prevent credit card fraud

Visualize DataOur eyes are extremely good at finding patterns

• Mathematical Graphs

• Statistical Diagrams

• Maps

• Timelines

• Network Graphs

Ice Bucket Challenge

https://srogers.cartodb.com/viz/89e638ac-2a2c-11e4-9cb7-0e73339ffa50/embed_map

10.000 hours of practice

Malcom Gladwell states in his book 'Outliers' that you need to practice for at least 10.000 hours in

order to master a specific skill.

8 hours/day * 7 days/week * 52 weeks/year * 3,5 year = 10192 uur

0,1%

Backup Slides

{ "coordinates": null, "created_at": "Thu Oct 21 16:02:46 +0000 2010", "favorited": false, "truncated": false, "id_str": "28039652140", "entities": { "urls": [ { "expanded_url": null, "url": "http://gnip.com/success_stories", "indices": [ 69, 100 ] } ], "hashtags": [   ], "user_mentions": [ { "name": "Gnip, Inc.", "id_str": "16958875", "id": 16958875, "indices": [ 25, 30 ], "screen_name": "gnip" } ] }, "in_reply_to_user_id_str": null, "text": "what we've been up to at @gnip -- delivering data to happy customers http://gnip.com/success_stories", "contributors": null, "id": 28039652140, "retweet_count": null, "in_reply_to_status_id_str": null, "geo": null, "retweeted": false, "in_reply_to_user_id": null, "user": { "profile_sidebar_border_color": "C0DEED", "name": "Gnip, Inc.", "profile_sidebar_fill_color": "DDEEF6", "profile_background_tile": false, "profile_image_url": "http://a3.twimg.com/profile_images/62803643/icon_normal.png", "location": "Boulder, CO", "created_at": "Fri Oct 24 23:22:09 +0000 2008", "id_str": "16958875", "follow_request_sent": false, "profile_link_color": "0084B4", "favourites_count": 1, "url": "http://blog.gnip.com", "contributors_enabled": false, "utc_offset": -25200, "id": 16958875, "profile_use_background_image": true, "listed_count": 23, "protected": false, "lang": "en", "profile_text_color": "333333", "followers_count": 260, "time_zone": "Mountain Time (US & Canada)", "verified": false, "geo_enabled": true, "profile_background_color": "C0DEED", "notifications": false, "description": "Gnip makes it really easy for you to collect social data for your business.",

top related