Python for Data Science, Essential Training Part 1


Course sections: Filter-Group-Sort | Data Visualization | Math Statistics | Web Scraping


6. Web Scraping


I. BeautifulSoup object 18m 28s
  • BS objects
    • Represents object as a whole.
  • Tag objects
    • XML and HTML objects
  • Navigateable string objects
    • Add text within a tag
    • NavigateableString class is container for text
  • Comment objects
    • A type of NavigateableString object

II. NavigableString objects 10m 1s
  • Text stored in tags

III. BeautifulSoup Data parsing 12m 42s
  • Pass HTML or XML to BeautifulSoup()

  • Get data from parse tree

  • find_all() method retrieves tags or strings to match filter

   Methods for searching

  • Name arg

  • Keyword arg

  • String arg

  • Lists

  • Booleans, Strings

  • Regular Expressions


IV. Web scraping in practice 10m 48s
  • Scrape a web page and write elements to file

V. Introduction to NLP 12m 31s
  • Natural Language Processing (NLP) with the Python Natural Language Toolkit (NLTK)

  • Sentence tokenization breaks out text into sentences

  • Produces an array with sentences as elements

  • Word tokenization breaks out text into words

  • Stop words add little or no meaning to a body of text

  • a, these, they’d, them, etc

VI. Cleaning and stemming textual data 7m 47s
  • Stemming reduce corpus by converting words to their root words

  • run vs run, ran, running

  • Root words may or may not have meaning when taken alone

  • Base words have meaning when taken alone, with only prefixes and suffixes attached

VII. Lemmatizing and analyzing textual data 10m 15s
  • Lemmatizing: converts raw word to base word; better -> good

  • Part of Speech tagging - process of identifying a part of speech within a body of text: Tagged output: [(‘I’,‘NN’), (‘is’,‘VBZ’), (‘cake’, ‘NN’)]

  • NN = Noun, singular; VBZ = Verb; NNS = noun plural; DT = Determiner; IN = Preposition

  • Freq Distribution Plotting: counts and plots the freq of words; 1st step toward quantifying the text corpus. Impt for sentiment analysis.


7. Collaborative Analytics with Plotly


I. Introduction to Plotly 4m 31s

Libraries

  • Plotly

  • cufflinks for pandas

Works with:

  • Excel

  • SQL

  • R

  • Python: numpy, pandas, matplotlib, jupyter

Use these attributes to generate plots from numpy objects:

  • Traces - describe a single variable of data in a graph; ie. scatterplot, or heatmap

  • Layouts - sets layout elements, i.e. title, x-axis, annotations

II. Create statistical charts 3m 28s
  • Linecharts

  • Barcharts

  • Statistical charts

IV. Bar charts and pie charts in Plotly 7m 24s
V. Create statistical charts 15m
  • Histograms

    • Simple histograms - Series object in simple interactive histogram.

    • Multiple histogram charts - DataFrame in overlapping histograms.

    • Subplot histograms - DataFrame in separate subplots.

  • Box Plots

  • Scatterplots

    • Set the ‘mode’ parameter to ‘markers’ to avoid lines between data points.

8. Conclusion