Category: How to

  • 9. How to clean data with Google Sheets functions (part 4): Split data

    #datacleaning #datapreparation #GoogleSheets

    How to split data from the following table with the GPS coordinates of the Colosseum in Rome, Italy to obtain latitude and longitude: insert SPLIT function in a new cell, A4 is the cell where the text is located, “-“ means that the text is divided based on minus sign.

  • 8. How to clean data with Google Sheets functions (part 1): Remove duplicates and COUNTIF functions

    #datacleaning #datapreparation #GoogleSheets

    Step 1: Remove any duplicates

    Select all columns, in the menu bar choose Data, then Data cleanup and select Remove duplicates.

    Click Data has header row andselect the columns where to remove duplicates i.e. column D for names

    Step 2: Clean up any data that does not make sense with COUNTIF function

    The COUNTIF function returns a conditional count across a range.

    Syntax

    COUNTIF(range, criterion)

    • range – The range that is tested against criterion.
    • criterion – The pattern or test to apply to range.

    i.e. COUNTIF(A2:A9, “Taxi”) to see how many Taxi entries are in the table rows A2:A9

  • 7. How to clean data with Google Sheets (part 2): delete extra spaces and change case in strings

    #datacleaning #datapreparation #GoogleSheets

    Further Cleaning data steps continued from the part 1 with the reference table available in https://docs.google.com/spreadsheets/d/1PkAbgXC7C1g2dKzCCpaHBcAyPw-s1z7iUxIEJ0cCYWQ/template/preview

    Step 3: Delete extra spaces in cells with string data

    Highlight the data in the spreadsheet, click on the Data tab, from Data cleanup select Trim whitespaces

    The following message explains that extra spaces were deleted in 4 cells:

    Step 4: Change case (upper and lower) text

    Google Sheets provides an Add-On for this task: click on the Add-ons option at the top of Google Sheets, click on Get add-ons and search for ChangeCase.

    To change the case, select the text to be edited, e.g. a column, click on the Add-Ons tab and select ChangeCase and select the option All lowercase or the needed option

    to obtain all lowercase in the selected column

    This step can be reverted with Clear formatting: click the Format tab and select the Clear Formatting option.

  • 6. How to clean data with Google Sheets: blank cells and transpose (part 1)

    #datacleaning #datapreparation #GoogleSheets

    Data cleaning includes several activities. This example is based on a hands-on activity of Google Data Analytics Professional issued by Coursera.

    Reference file is available here:

    https://docs.google.com/spreadsheets/d/1PkAbgXC7C1g2dKzCCpaHBcAyPw-s1z7iUxIEJ0cCYWQ/template/preview

    Step 1: Find blank cells

    Highlight all cells in the spreadsheet, click on Data e select Create a filter

    To review a list of all the rows with blank cells, in the Order date column Filter by condition (is empty) and click OK:

    After managing these cells, turn off this filter with Filter by condition (None).

    Step 2: Transpose

    Transposing=convert the data from long format (more rows than columns) to wide format (more columns than rows).

    Highlight and copy data to be transposed including column labels (e.g. columns A1-H45). Then select a new cell (J2) and Paste special with Transpose option.

    Delete the old table.

  • 5. How to query public data with SQL

    #BigQuery #SQL #publicdata

    Open Google BigQuery Console and in the Explorer pane, select the Add + button.

    In the pop-up window select Public dataset:

    Search a subject in the Marketplace field, e.g. “job”, to see US job related dataset

    Select a dataset:

    Select the View dataset button, BigQuery opens Public dataset in Explorer pane

    Type your search term in the search text field, e.g. employment, to see the available tables:

    Select the first table to see the employment hours earnings table structure.

    Click on Preview to see the table content:

    Select query in new tab:  

    Write the following query to see the average value for these hour earnings

    SELECT AVG(value) FROM `bigquery-public-data.bls.employment_hours_earnings` LIMIT 1000

    This result can be validated with the related xls file

  • 4. How to write a simple SQL Query in Big Query

    #SQL #queries #BigQuery

    Starting from the custom table I created here, click on Query:

    Start writing your query from this pane

    Question: Which are the Top 5 Most Common male Birth Names in Italy in 1999?

    In SQL pane write:

    SELECT

      nome,

      nati

    FROM `nasciteitalia.datinasciteItalia.diffusionenomi`

    WHERE

      anno=1999

    ORDER BY

      nati DESC

    LIMIT

      5

    This query selects from the data table ‘diffusionenomi’ in database ‘datinasciteItalia’ in project ‘nasciteitalia’ the  two columns (‘nome’ and ‘nati’) for the year ‘1999’ and sorts these two columns in descending order limiting the results to 5 items.

    Click RUN to see the results:

    Check with the reference table from Istat:

  • 3. How to create a custom table in BigQuery from an Excel file (e.g. Istat database for birth names in Italy)

    From BigQuery console create a new project:

    Create a new dataset clicking on the three dots in the Explorer pane:

    Select this new dataset to create a new table clicking on + Create table:

    [As an example, I downloaded an Excel file from

    https://demo.istat.it/app/?i=FE3&l=it

    Then the Excel file was converted in CSV, saved as .txt and simplified with these 3 columns:

    Immagine che contiene testo, schermata, Carattere, numero

Il contenuto generato dall'IA potrebbe non essere corretto.]

    To create a table in Big Query from this file, select +Create table:

    Then Upload your table in CSV format, detailing data format with a schema (Anno=integer,Nome=string,Nati=integer)

    Immagine che contiene testo, schermata, numero, Carattere

Il contenuto generato dall'IA potrebbe non essere corretto.Click on the new table to see a preview:

    Compare to the txt file uploaded to check the results:

  • 2. How to create a free Google BigQuery account for SQL knowledge

    To set up a sandbox account:

    1. Visit the BigQuery sandbox documentation page.
    1. Log in to your preferred Google account by selecting the profile icon in the BigQuery menu bar.
    2. Select the Go to BigQuery button on the documentation page.
    3. You’ll be prompted to select your country and read the terms of service agreement.
    4. This will bring you to the SQL Workspace, where you’ll be conducting upcoming activities. By default, BigQuery creates a project for you.

    After you set up your account, the name of the project will be in the banner in your BigQuery console.

  • 1. Data cleaning (sorting and filtering) with Google Sheets

    1. Data cleaning (sorting and filtering) with Google Sheets

    Data cleaning based on a hands-on activity of Google Data Analytics Professional issued by Coursera

    Skills: #datacleaning #filtering #GoogleSheets

    Goal: understand how to improve the performance of students in a public school. Data source: reports and surveys of two public schools (named GP, MS). Information included in data: student grades, background information, study time, participation in extracurricular activities.

    Access to Google sheet file https://docs.google.com/spreadsheets/d/1lekmvxJDglmqUKxSxSk7TiA8Sfurqc9pTyKXIgUvNm4/template/preview?resourcekey=0-O8LBUyc6VTc9sYPH6hdsmw#gid=1019073941 to download and follow step by step

    Click on the top right corner (Use model) to get a working copy

    Rename the spreadsheet

    Before sorting, select all the data

    Sort from menu: Data->Sort Range->Advanced

    Then sort by school and by age

    To obtain

    Potential issue: scrolling through the data, you see that the age range of the students at GP school is 15-22 years, and the age range of the students at MS school is 15-20 years.

    Filtering to add a restraint: the age range should be 15-19 for both schools. Any student outside this age range should be deleted from the dataset: i.e. remove the ages 20, 21, and 22 from the dataset. To apply a filter to the age column, select the age column by clicking the letter at the top of the column.

    From the menu bar, select Data, then Create a filter

    Click on the filter icon (highlighted in yellow) to deselect 20, 21 and 22

    To obtain

    Turn off filter:  Data and Turn off filter

    Filling in missing data

    Student’s reason for choosing a specific school is important to know for this analysis: the reason column should be complete and without blanks. Apply a filter across the entire spreadsheet, clicking on any cell in the sheet. Then, from the menu bar, select Data and Create a filter.

    Click the Filter icon on the reason column (K). Filter this column for blanks by unchecking all the other values (course, home, reputation).

    Replace the missing values with the value, e.g. none_given. To do this while the column is still filtered for blanks, enter none_given in the first empty cell (K38). Then, press Enter. Immagine che contiene testo, schermata, Carattere, numero

Il contenuto generato dall'IA potrebbe non essere corretto.

    Double click the fill handle to fill all the other blank cells with the value none_given.

    Turn off filter