![Page 1: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/1.jpg)
Social Media & Text Analysis part 1 - Intro to Python
OhioStateUniversityInstructor:WeiXu
Website:socialmedia-class.org
![Page 3: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/3.jpg)
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
![Page 4: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/4.jpg)
Wei Xu ◦ socialmedia-class.org
Simplicity of Python• Create a list of integers:
• Python
• Java, in contrast:
Source: http://amontalenti.com/pub/python-training/
![Page 5: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/5.jpg)
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/
![Page 6: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/6.jpg)
Wei Xu ◦ socialmedia-class.org
• Create a list of integers, and print them out:
Simplicity of Python
output
![Page 7: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/7.jpg)
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, … ]
![Page 8: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/8.jpg)
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
![Page 9: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/9.jpg)
Wei Xu ◦ socialmedia-class.org
output
• Create a list of integers, and print them out:
Simplicity of Python
simple and very useful print() function
![Page 10: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/10.jpg)
Wei Xu ◦ socialmedia-class.org
• Create a list of integers, and print them out:
Simplicity of Python
Indentation is very important in Python!
![Page 11: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/11.jpg)
Wei Xu ◦ socialmedia-class.org
Try it Out! • We will use Google's Colab programming environment:
![Page 12: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/12.jpg)
Wei Xu ◦ socialmedia-class.org
Basic String Operations• A Code Sample:
![Page 13: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/13.jpg)
Wei Xu ◦ socialmedia-class.org
• A Code Sample:
Basic String Operations
Characters in a string can be assessed using the [] syntax.
output
![Page 14: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/14.jpg)
Wei Xu ◦ socialmedia-class.org
• A Code Sample:
Basic String Operations
The len(string) function returns the length of a string.
![Page 15: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/15.jpg)
Wei Xu ◦ socialmedia-class.org
• A Code Sample:
Basic String Operations
The str() function converts values to a string data type.
output
![Page 16: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/16.jpg)
Wei Xu ◦ socialmedia-class.org
• A Code Sample:
Basic String Operations
The + operator can concatenate two strings.
output
![Page 17: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/17.jpg)
Wei Xu ◦ socialmedia-class.org
• A Code Sample:
Basic String Operations
The split() function returns a list of substrings.
output
![Page 18: Social Media & Text Analysissocialmedia-class.org/slides_highschool/15min_intro... · 2020-03-24 · Social Media & Text Analysis part 1 - Intro to Python Ohio State University Instructor:](https://reader034.vdocuments.us/reader034/viewer/2022050104/5f42b93a53d29b327f2ce776/html5/thumbnails/18.jpg)
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