Data Wrangling
Week 5
Dr. Ferdin Joe John Joseph
Faculty of Information Technology
Thai – Nichi Institute of Technology, Bangkok
Today’s Lesson
• Introduction to JSON
• JSON - Theories
• JSON parsing using Python
• Demonstration
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
2
JSON – Introduction
• JSON stands for Java Script Object Notation
• It is a subset of Javascript
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
3
JSON
Javascript
Java
Forms of JSON
• Objects
• Arrays
• Values
• Strings
• Whitespace
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
4
JSON Objects
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
5
JSON Objects
• An object is an unordered set of name ‘/’ value pairs.
• An object begins with ‘{‘ left brace and ends with ‘}’ right brace.
• Each name is followed by ‘:’ colon and the name ‘/’ value pairs are
separated by ‘,’ comma.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
6
JSON Arrays
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
7
JSON Arrays
• An array is an ordered collection of values.
• An array begins with ‘[‘ left bracket and ends with ‘]’ right bracket.
• Values are separated by ‘,’ comma.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
8
JSON Values
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
9
JSON Values
• A value can be a string in double quotes, or a number, or true or false
or null, or an object or an array.
• These structures can be nested.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
10
JSON String
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
11
JSON String
• A string is a sequence of zero or more Unicode characters, wrapped in
double quotes, using backslash escapes.
• A character is represented as a single character string. A string is very
much like a C or Java string.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
12
JSON Numbers
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
13
JSON Whitespace
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
14
JSON Protocol
• ECMA-404 The JSON Data Interchange Standard.
• Link of the protocol in canvas. For your reading
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
15
Usage of JSON in python
• Demonstration in Jupyter
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
16
Prerequisite
• Prepare a JSON file using notepad and save it as filename.json
• For easy access, save the file in the same directory as the ipynb
notebook
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
17
Prerequisite
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
18
Prerequisite
• You can also download from canvas.instructure
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
19
Libraries
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
20
Libraries
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
21
JSON in variable
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
22
JSON from file
• Create a file person.json and store the following
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
23
{"name": "Bob",
"languages":
["English", "French"]
}
JSON file read
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
24
Dict to JSON
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
25
Read and write JSON
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
26
Add more fields
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
27
Append more data
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
28
Read Data
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
29
Append Entries
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
30
Read JSON from URL
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
31
Activity
• Read the JSON content in the link below and perform data analysis on
the data parsed. Show the columns removed and data wrangling
done to make the data presentable. Upload to your GitHub and
submit the link of your ipynb file in canvas.instructure portal.
https://covid19.th-stat.com/api/open/cases
Classwork and graded assignment
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
32
Lesson for Next Week
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
https://github.com/ferdinjoe/DSA201
33

Data wrangling week 5

  • 1.
    Data Wrangling Week 5 Dr.Ferdin Joe John Joseph Faculty of Information Technology Thai – Nichi Institute of Technology, Bangkok
  • 2.
    Today’s Lesson • Introductionto JSON • JSON - Theories • JSON parsing using Python • Demonstration Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 2
  • 3.
    JSON – Introduction •JSON stands for Java Script Object Notation • It is a subset of Javascript Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 3 JSON Javascript Java
  • 4.
    Forms of JSON •Objects • Arrays • Values • Strings • Whitespace Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 4
  • 5.
    JSON Objects Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 5
  • 6.
    JSON Objects • Anobject is an unordered set of name ‘/’ value pairs. • An object begins with ‘{‘ left brace and ends with ‘}’ right brace. • Each name is followed by ‘:’ colon and the name ‘/’ value pairs are separated by ‘,’ comma. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 6
  • 7.
    JSON Arrays Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 7
  • 8.
    JSON Arrays • Anarray is an ordered collection of values. • An array begins with ‘[‘ left bracket and ends with ‘]’ right bracket. • Values are separated by ‘,’ comma. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 8
  • 9.
    JSON Values Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 9
  • 10.
    JSON Values • Avalue can be a string in double quotes, or a number, or true or false or null, or an object or an array. • These structures can be nested. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 10
  • 11.
    JSON String Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 11
  • 12.
    JSON String • Astring is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. • A character is represented as a single character string. A string is very much like a C or Java string. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 12
  • 13.
    JSON Numbers Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 13
  • 14.
    JSON Whitespace Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 14
  • 15.
    JSON Protocol • ECMA-404The JSON Data Interchange Standard. • Link of the protocol in canvas. For your reading Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 15
  • 16.
    Usage of JSONin python • Demonstration in Jupyter Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 16
  • 17.
    Prerequisite • Prepare aJSON file using notepad and save it as filename.json • For easy access, save the file in the same directory as the ipynb notebook Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 17
  • 18.
    Prerequisite Faculty of InformationTechnology, Thai - Nichi Institute of Technology, Bangkok 18
  • 19.
    Prerequisite • You canalso download from canvas.instructure Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 19
  • 20.
    Libraries Faculty of InformationTechnology, Thai - Nichi Institute of Technology, Bangkok 20
  • 21.
    Libraries Faculty of InformationTechnology, Thai - Nichi Institute of Technology, Bangkok 21
  • 22.
    JSON in variable Facultyof Information Technology, Thai - Nichi Institute of Technology, Bangkok 22
  • 23.
    JSON from file •Create a file person.json and store the following Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 23 {"name": "Bob", "languages": ["English", "French"] }
  • 24.
    JSON file read Facultyof Information Technology, Thai - Nichi Institute of Technology, Bangkok 24
  • 25.
    Dict to JSON Facultyof Information Technology, Thai - Nichi Institute of Technology, Bangkok 25
  • 26.
    Read and writeJSON Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 26
  • 27.
    Add more fields Facultyof Information Technology, Thai - Nichi Institute of Technology, Bangkok 27
  • 28.
    Append more data Facultyof Information Technology, Thai - Nichi Institute of Technology, Bangkok 28
  • 29.
    Read Data Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 29
  • 30.
    Append Entries Faculty ofInformation Technology, Thai - Nichi Institute of Technology, Bangkok 30
  • 31.
    Read JSON fromURL Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 31
  • 32.
    Activity • Read theJSON content in the link below and perform data analysis on the data parsed. Show the columns removed and data wrangling done to make the data presentable. Upload to your GitHub and submit the link of your ipynb file in canvas.instructure portal. https://covid19.th-stat.com/api/open/cases Classwork and graded assignment Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 32
  • 33.
    Lesson for NextWeek Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok https://github.com/ferdinjoe/DSA201 33