Programmieren lernen
PacmanÜber mich
English
English
  • Course Outline
  • 1 - Databricks
    • Getting Started
    • Working with Notebooks
      • Adding Documentation
      • Built-In Visualizations
      • Import Data
      • Export Data
  • 2 - Introduction
    • Types of Questions
      • Finding Individual Records
      • Summarizing Data
      • Exploring Data
      • Drawing Inferences From Data
      • Predicting Information
      • Finding Causality
    • Steps in Data Analytics
    • Dimensions of Data Sets
    • Dimensions of Records
    • Dimensions of Fields
    • Data Types and Scales
  • 3 - SQL
    • Basic SQL
      • What is SQL?
      • Import Data
      • Select Columns
      • Filter Rows
      • Aggregate and Group Rows
      • Filter Aggregated Rows
      • Sort Rows
    • Advanced SQL
      • Views
      • Set Operators
      • Subqueries
      • Window Functions
      • Date and Time
      • Arrays
      • JSON
      • Statistical Analysis
    • Multiple Data Sets with SQL
    • Text with SQL
      • Search Text
      • Analyzing Words
        • Prefilter the Data
        • Clean and Normalize
        • Tokenize and Count
        • Filter Stop Words
        • POS Tagging
      • Word Pairs
      • Extract Emoticons
  • 4 - Python
    • Python for Data Analytics
      • What is Python?
    • Natural Language Processing
  • 5 - R
    • R Basics
  • 6 - Visualization
    • Why Visualize Data?
    • Data Visualization with R
    • Types of Visualizations
      • Developments and Trends
      • Distributions
    • Pitfalls in Data Visualization
  • 7 - Tableau
    • Getting Data Into Tableau
  • 8 - Spreadsheets
    • What Is A Spreadsheet?
  • Data & Exercises
    • Simpsons
    • Covid19
    • TED Talks
    • Lemonade Market Research
    • Chicago Crimes
    • Tweets of German Politicians
    • Amazon Product Reviews
    • REWE Online Products
Powered by GitBook
On this page

Was this helpful?

  1. 3 - SQL
  2. Text with SQL
  3. Analyzing Words

Tokenize and Count

PreviousClean and NormalizeNextFilter Stop Words

Last updated 4 years ago

Was this helpful?

Aus einem Text werden mehrere Zeilen

Der View aus dem gibt uns eine bereinigte und normalisierte Form des Ursprungs-Tweets. Aus:

RT @pugandcat: Whisker licking good food from @lilyskitchen

wird:

rt pugandcat whisker licking good food from lilyskitchen

Nun ist es Zeit, aus dem zusammenhängenden Text einzelne Wörter zu erstellen. Dabei hilft uns die Funktion split():

create or replace view tweets_words as
  select user
        ,created_at
        ,split(text, ' ') as `words`
  from tweets_cleaned

Das split(text, ' ') in Zeile 4 hat zur Folge, dass wir in der neuen Spalte words dieses Ergebnis sehen:

["rt","pugandcat","whisker","licking","good","food","from","lilyskitchen"]

Kommt euch das bekannt vor? Richtig! Es handelt sich um ein Array, was wir an den eckigen Klammern außen erkennen können. Arrays können wir mit explode() in seine Einzelteile zerlegen, sodass wir jedes Element in einer eigenen Zeile vorliegen haben:

-- Array von Wörtern in Zeilen zerlegen
select explode(words) as `word` from tweets_words

Wenn wir nun beide Funktionen verschachtelt anwenden, haben wir unseren fertigen View für Schritt 3:

create or replace view tweets_words as
select id
      ,screen_name
      ,created_at
      ,lang
      ,posexplode(split(text, ' ')) as (position, word)
from tweets_cleaned

Schritt 2