social media & text analysissocialmedia-class.org/slides_highschool/15min_intro... ·...

Post on 13-Jul-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Social Media & Text Analysis part 1 - Intro to Python

OhioStateUniversityInstructor:WeiXu

Website:socialmedia-class.org

Wei Xu ◦ socialmedia-class.org

Wei Xu ◦ socialmedia-class.org

Why Python?• Python is an object-oriented and high level programming

language (first released in 1991).

• Very beginner-friendly! - shorter code needed for the same task.

• Very powerful! - many well-maintained libraries (e.g. numpy, Matplotlib,

Scikit-learn, PyTorch, TensorFlow,) - a popular programming language in AI and machine

learning research

Wei Xu ◦ socialmedia-class.org

Simplicity of Python• Create a list of integers:

• Python

• Java, in contrast:

Source: http://amontalenti.com/pub/python-training/

Wei Xu ◦ socialmedia-class.org

Simplicity of Python• Create a list of integers, and print them out:

• Python

• Java, in contrast:

Source: http://amontalenti.com/pub/python-training/

Wei Xu ◦ socialmedia-class.org

• Create a list of integers, and print them out:

Simplicity of Python

output

Wei Xu ◦ socialmedia-class.org

• Create a list of integers, and print them out:• Create a list of integers, and print them out:

Simplicity of Python

Lists are declared using [item1, item2, item3, … ]

Wei Xu ◦ socialmedia-class.org

output

• Create a list of integers, and print them out:

Simplicity of Python

Iterates over each item in the list, yielding (index, value) tuples

Wei Xu ◦ socialmedia-class.org

output

• Create a list of integers, and print them out:

Simplicity of Python

simple and very useful print() function

Wei Xu ◦ socialmedia-class.org

• Create a list of integers, and print them out:

Simplicity of Python

Indentation is very important in Python!

Wei Xu ◦ socialmedia-class.org

Try it Out! • We will use Google's Colab programming environment:

Wei Xu ◦ socialmedia-class.org

Basic String Operations• A Code Sample:

Wei Xu ◦ socialmedia-class.org

• A Code Sample:

Basic String Operations

Characters in a string can be assessed using the [] syntax.

output

Wei Xu ◦ socialmedia-class.org

• A Code Sample:

Basic String Operations

The len(string) function returns the length of a string.

Wei Xu ◦ socialmedia-class.org

• A Code Sample:

Basic String Operations

The str() function converts values to a string data type.

output

Wei Xu ◦ socialmedia-class.org

• A Code Sample:

Basic String Operations

The + operator can concatenate two strings.

output

Wei Xu ◦ socialmedia-class.org

• A Code Sample:

Basic String Operations

The split() function returns a list of substrings.

output

Wei Xu ◦ socialmedia-class.org

More Resources• Python :

- Google’s class: https://developers.google.com/edu/python/ - Christophe Morisset’s notebook:

https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Python.pdf

- and many others …

• Got a Error Messages or questions? - Search on Google - StackOverflow

top related