Deciphering Data to Uncover Hidden Insights — Data Wrangling and Ingestion
This multi-part article talks about how to collect data, wrangle the data, ingest the data, model the data, and visualize the data from three viewpoints (conceptual, practical, and best practice).
In the first article of this series, we have seen how to understand data conceptually through an example from the Banking, Financial services and Insurance (BFSI) domain.
In this article, we will learn how to wrangle the data (i.e. cleaning the data) according to your business scenario to Alibaba Cloud Quick BI. We may need Quick BI in the upcoming process of deciphering data so please ensure that you have registered for an Alibaba Cloud account. If you haven’t, sign up for a free account through this link.
What Is Data Wrangling
Data wrangling, sometimes referred as data munging, is the process of transforming data from one format to other with the intent of making it more appropriate and valuable for analytics. With the rapid rise of Big Data and IoT applications, the number of data types and formats are increasing each day. This makes data wrangling an indispensable element for big data processing, especially for larger applications.
What Is Quick BI
Alibaba Cloud Quick BI is a flexible and lightweight business analytics platform built on cloud. The basic components of Quick BI are as follows:
- Data source
- Worksheet (Quick BI Basic)
- Workbook (Quick BI Pro and Professional edition)
- Portal (Quick BI Pro and Professional edition)
Wrangle the Data (Conceptual)
Data wrangling includes:
- Data Cleaning
- Data Editing
Data cleansing or data cleaning is the process of detecting, analyzing, removing the inaccurate records from a data set, and replacing the inaccurate parts of the data by appropriate data. Data cleansing could be done with help of data wrangling tools, or through scripts.
For example, let’s assume the dataset has some erroneous value in date column like “s29–05–2018” instead of “29–05–2018”. To a person, this may seem like a trivial error, but to a system, this entry is unreadable. The system may not read this entry as a date but instead it will take it as a string.
Note: We can use Excel itself to clean the data but may we miss something. It’s better to do it via scripts or tools. If the data source is Database, then we can do it in BI tool.
Data Editing and Preparing
Data Editing and Preparing is nothing but a manual process of changing the data, data types for the reporting purpose.
For example, let’s assume dataset has date values in “MM-DD-YYYY” format but we need in “DD-MM-YYYY” format. This means we need to change it manually.
Note: Data Editing and Preparing is usually carried out in Excel itself or if the data source is Database then we can do it in BI tool.
Wrangle the Data (Practical)
As we discussed earlier, we are going to use Excel to wrangle the data. In addition to that, I also like to share the python script I wrote to wrangle the data automatically.
UseCase-1: ATM Analytics
Here, we will look at our first use case ATM Dataset. In this use case example we will see how to wrangle the data in Excel.
Our dataset is clean, but for demonstration we will make some part of this data erroneous or inaccurate first.
Now our data contains some erroneous value like:
- Transaction Date has some erroneous data, so it recognizes the columns as String instead of Date.
- No of Withdraws must contain whole number but it contains decimal number.
- Working Day contains one small h which makes it has new categorical value.
- Working Day, Holiday Sequence also contains erroneous data.
We need to handle this because if not handled properly it will lead to inaccurate results which in turn leads to false insights.
Let me show how to handle this in excel. Please have a look at the following table
TypeResultNumber1Text2Logical Value4Error Value16Array Value64
Using Type Function, we can easily find erroneous data. Please follow the following Steps:
- Insert a new column for validating the data
- Write the formula “=TYPE(Range)”
- Apply Filter to the column to validate
From this we can easily find whether date column has erroneous value or not. Because it contains text, we can differentiate text vs number but we couldn`t able to find whether it has float instead of integer. We may also use other functions in this process say like ISNUMBER(), ISTEXT, Etc.,
We may not able to analyze each cell to find the incorrect data. So, it is essential to use any wrangling tool or scripts.
UseCase-2: Customer 360
Here we go our next use case Customer360.
We are going to use a Python Script to wrangle the data automatically. I will write a separate article in detail about this programmatic approach to “Decipher the data to uncover the hidden insights out of it”.
# #Importing the necessary modules
# =============================================================================import pandas as pd
import numpy as np# =============================================================================
# #Data Wrangling or Data munging
# =============================================================================def datawrangler(data):
data.rename(columns=lambda x: x.replace(' ', ''), inplace=True)
# Getting Column Names
# Getting Column Types
#Adding Column types with their respective columns
for x in range(len(columns)):
if (columns['ColumnTypes'].iloc[x]) is np.dtype(np.int64) or (columns['ColumnTypes'].iloc[x]) is np.dtype(np.float64) :
if (columns['ColumnTypes'].iloc[x]) is not np.dtype(np.int64):
if 'date' in (columns['ColumnFields'].apply(np.str.lower).iloc[x]):
data[columns['ColumnFields'].iloc[x]]=data[columns['ColumnFields'].iloc[x]].apply(pd.to_datetime) if (columns['ColumnTypes'].iloc[x]) is np.dtype(np.float64):
for y in range(len(data)):
if (np.modf(data[columns['ColumnFields'].iloc[x]].iloc[y])) in ['0.0',0.0] :
if (columns['ColumnTypes'].iloc[x]) is not np.dtype(np.int64) and (columns['ColumnTypes'].iloc[x]) is not np.dtype(np.float64) and ('date' not in (columns['ColumnFields'].apply(np.str.lower).iloc[x])):
for y in range(len(data)):
if ((data[columns['ColumnFields'].iloc[x]].iloc[y]).isnumeric()) :
# #Getting the Data
# =============================================================================location=input("\n\nEnter the File Location\n\n\t")
savelocation=input("\n\nEnter the File Save Location\n\n\t")# =============================================================================
# #Passing the Data to the Module
data.to_csv(savelocation, index=False, header=None)
Wrangle the Data (Best Practices)
- It’s always a best practice to check whether the data is clear or need to be wrangled.
- Check the data whether it has anomalies, and outliers.
- Convert the categorical values to lower or upper case and then convert it to sentence case to avoid repetition of same values
- Find null values and NaN values which leads to false results.
- Use Data Wrangler or Preparation tools to wrangle the data to avoid human error.
Ingest the Data (Conceptual)
Data ingestion is a critical success factor for analytics and business intelligence. We need to know about OLTP and OLAP.
OLTP is an Online Transaction Processing system. The focus of OLTP system is to record the current Update, Insertion and Deletion while transaction. The OLTP queries are simpler and short and hence require less time in processing and requires less space. A common example of an OLTP system is an ATM database, in which using short transactions we modify the status of our account
OLAP, on the other hand, is an Online Analytical Processing system. OLAP database stores historical data that has been inputted by OLTP. Using OLAP, you can extract information from a large database and analyze it for decision making. A classic example of an OLAP system is a data warehouse, which accumulates data from multiple OLTP data sources for querying and analyzing the data.
For both OLTP and OLAP, we may have files or database as data sources. Typical file formats include .CSV and .XLS. We also need to consider different types of databases for our application. Connectors will be available to easily connect the databases.
Ingest the Data (Practical)
Let’s now see how to ingest data into Quick BI.
But first, you’ll need to have Quick BI set up for this example. Follow these steps to apply for Quick BI Pro Trial. You’ll need to have an Alibaba Cloud account. If you don’t have one already, please sign up here.
- You’ll need to have an Alibaba Cloud account. If you don’t have one already, please sign up here. Log in to your Alibaba Cloud account.
- Enter your Console and navigate to the Quick BI product console.
- Select the Region and Select Quick BI Pro.
Your Quick BI instance has been created.
How to Ingest Files into Quick BI Pro
- Select Personal Workspace
- Click the Data Source, Click Upload, Upload the file, Name the file, and Click Ok.
- Data is successfully ingested into Quick BI.
Note: Files are only supported in personal workspace.
How to Ingest Data from Database to Quick BI Pro
- Select Default Workspace
- Click the Data Source, Click Create Data Source, Select the Data Source
- Note: You can select either Cloud Databases or External Databases.
- Fill the Connection Details, Click Test Connection, and Save
- Data source connection is established.
Note: Please choose workspace other than the personal workspace so that you can able to use workbooks.
Ingest the Data (Best Practices)
- Always Ingest the Wrangled data if you are using files.
- Don’t connect OLTP Database as source as doing so may degrade the performance of source systems.
- Connect the OLAP Databases or Use RDS Services offered by Alibaba Cloud Platform.
- Always use custom query to ingest the data instead of ingesting all tables.
If you followed the steps correctly, you should have successfully ingested data into Quick BI, which is a great milestone in the process of deciphering your data to uncover the hidden insights.
Please ensure that you have registered for an Alibaba Cloud account to enjoy a free trial of Quick BI Pro. In the next article of this multi-part tutorial, we will see how to model the data with Quick BI. See you all in next part of this article series.