Difference between revisions of "The Indian Story Data Prep"

From Visual Analytics and Applications
Jump to navigation Jump to search
Line 1: Line 1:
<div style=background:#2B3856 border:#A3BFB1>
+
<div style=background:#001a66 border:#A3BFB1>
 
[[File:Banner.png|600px]]
 
[[File:Banner.png|600px]]
 
<font size = 6; color="#FFFFFF">''Group 9-The Indian Story''</font>
 
<font size = 6; color="#FFFFFF">''Group 9-The Indian Story''</font>
Line 5: Line 5:
  
 
{|style="background-color:#1B338F;" width="100%" cellspacing="0" cellpadding="0" valign="top" border="0"  |
 
{|style="background-color:#1B338F;" width="100%" cellspacing="0" cellpadding="0" valign="top" border="0"  |
| style="font-size:100%; solid #000000; background:#2B3856; text-align:center;" width="20%" |  
+
| style="font-size:100%; solid #000000; background:#001a66; text-align:center;" width="20%" |  
 
[[The_Indian_Story| <font color="#FFFFFF">Project Proposal</font>]]
 
[[The_Indian_Story| <font color="#FFFFFF">Project Proposal</font>]]
  
| style="font-size:100%; solid #1B338F; background:#2B3856; text-align:center;" width="20%" |  
+
| style="font-size:100%; solid #1B338F; background:#b30000; text-align:center;" width="20%" |  
 
[[The_Indian_Story_Data_Prep| <font color="#FFFFFF">Data Preparation</font>]]
 
[[The_Indian_Story_Data_Prep| <font color="#FFFFFF">Data Preparation</font>]]
  
| style="font-size:100%; solid #1B338F; background:#2B3856; text-align:center;" width="20%" |  
+
| style="font-size:100%; solid #1B338F; background:#001a66; text-align:center;" width="20%" |  
 
[[The_Indian_Story_Poster| <font color="#FFFFFF">Poster</font>]]
 
[[The_Indian_Story_Poster| <font color="#FFFFFF">Poster</font>]]
  
| style="font-size:100%; solid #1B338F; background:#2B3856; text-align:center;" width="20%" |  
+
| style="font-size:100%; solid #1B338F; background:#001a66; text-align:center;" width="20%" |  
 
[[The_Indian_Story_Application| <font color="#FFFFFF">Application</font>]]
 
[[The_Indian_Story_Application| <font color="#FFFFFF">Application</font>]]
  
| style="font-size:100%; solid #1B338F; background:#2B3856; text-align:center;" width="20%" |  
+
| style="font-size:100%; solid #1B338F; background:#001a66; text-align:center;" width="20%" |  
 
[[The_Indian_Story_Report| <font color="#FFFFFF">Report</font>]]
 
[[The_Indian_Story_Report| <font color="#FFFFFF">Report</font>]]
  

Revision as of 20:15, 17 July 2017

Banner.png Group 9-The Indian Story

Project Proposal

Data Preparation

Poster

Application

Report


from the data engineers desk

Data

Here we speak about the dataset and munging that we do upon it. In order to create the visualisations and eventually build the Application it is important to have the data in the right form. Let's start with examining the data in its initial form.

Data as downloaded from the website

The copy of the data can be downloaded from this link here

Here is a portion of the data excel data source that somewhat gives us an overview of the data. I'll explain more in the tables below. Sometimes visually looking at the data helps flare off ideas on how to munge it.

Project was data.JPG

The data file is quite a clean file with no missing values. Those with no values are replaced with 0 and they are all in terms of population numbers. No ratios have been computed except for totals. A glance at the data file above will give you the impression that there is more than one level of data and that information is in the hierarchical form. The picture below is what we visualise the dataset to be conceptually.

width = 100

Every row has certain data attributes. Population information in each row has a hierarchial structure beginning with the state code followed by the city/town name then whether it is an Urban or a rural city and finally the age group. Here however there isn't a particular state name given for the state code. This is where the second dataset comes in and helps us understand the meaning of the state codes.

Next the variables also have a hierarchial structure. You have the highest level popluation totals. These tell you total population, total male population and total female population. Then following that you have the division of Illiterate and Literate population numbers. Both of these have persons, male and female divisions. Next under Literate you have those with education and those without education. Again under Literate and without education you have population total number of male and female numbers. Then under Literate with education, you have the different levels of education! They go all the way from before Primary to Graduates. Then under each of these categories you have population numbers for total, male and female.

So let's start addressing one data problem after another. The following explains the problem and the solution used to solve them.

Data Problem 1: Break the hierarchy

Problem

So the dataset itself came with a hierarchy which needed to be broken down.

Solution

This was done manually on excel. Although Python and R have code logic that can be used to merge the cells. The output of the new column names is printed here. This sheet was then stored as table 1.

 
TableName
State Code
Town Code
Town Name
Urban/Rural
Age-group
Persons.Total
Males.Total
Females.Total
Persons.Illiterate
Males.Illiterate
Females.illiterate
Persons.Literate
Males.Literate
Females.Literate
Persons.L.NoEdu
Males.L.NoEdu
Females.L.NoEdu
Persons.BelowPrim
Males.BelowPrim
Females.BelowPrimary
Persons.P
Males.P
Females.P
Persons.M
Males.M
Females.M
Persons.S
Males.S
Females.S
Persons.PreUni
Males.PreUni
Females.PreUni
Persons.Diploma(NT)
Males.Diploma(NT)
Females.Diploma(NT)
Persons.Diploma(T)
Males.Diploma(T)
Females.Diploma(T)
Persons.Graduates
Males.Graduates
Females.Graduates
Persons.Unclassified
Males.Unclassified
Females.Unclassified

Data Problem 2: State Codes are not Sufficient!

Problem Definition

Imagine if you read a map, hover over a particular state in India and all you get to see is the state code. Unless you are an educated Indian, you wouldn't know what that means. Hence the second dataset was used. This can be downloaded here


Solution

We wrote a beautiful R code to munge this.

 
# Level one cleaning 
## Import data 
table1<- readxl::read_excel("Table 1.xlsx")
table2 <- readxl::read_excel("Table 2.xlsx")

## get the state code to name dictionary 
cl_table2 <- table2 %>% distinct()

## recode it into the State Code column of the original table
table1$`State Code`<- recode(table1$`State Code`, "01" = "JAMMU & KASHMIR",
                             "02" = "HIMACHAL PRADESH",
                             "03" = "PUNJAB",
                             "04" = "CHANDIGARH" ,
                             "05" = "UTTARAKHAND",
                             "06" = "HARYANA" ,
                             "07" = "NCT OF DELHI",
                             "08" = "RAJASTHAN",
                             "09" = "UTTAR PRADESH",
                             "10" = "BIHAR",
                             "13" = "NAGALAND",
                             "14" = "MANIPUR",
                             "15" = "MIZORAM",
                             "16" = "TRIPURA",
                             "17" = "MEGHALAYA",
                             "18" = "ASSAM",
                             "19" = "WEST BENGAL",
                             "20" = "JHARKHAND",
                             "21" = "ORISSA",
                             "22" = "CHHATTISGARH",
                             "23" = "MADHYA PRADESH",
                             "24" = "GUJARAT",
                             "27" = "MAHARASHTRA",
                             "28" = "ANDHRA PRADESH",
                             "29" = "KARNATAKA",
                             "32" = "KERALA",
                             "33" = "TAMIL NADU",
                             "34" = "PUDUCHERRY",
                             "35" = "ANDAMAN & NICOBAR ISLANDS")


Data Problem 3: The Table has too many variables and is too broad

Problem

Data lessons say that it is easier to work with data tables that are narrow. This table was too broad with many variables. These variables could be converted to categories instead and put into a column.

Solution

We used the gather function of the tidyverse library in R

 
#Gather table
gather_table <- table1 %>% gather("Literacy Level","Population",7:45)

#rename some values so that we can run the separation
gather_table$`Literacy Level`<- as.factor(gather_table$`Literacy Level`)
gather_table$`Literacy Level`<- recode(gather_table$`Literacy Level`,  Females.L.NoEdu="Females.L_NoEdu" )
gather_table$`Literacy Level`<- recode(gather_table$`Literacy Level`,  Males.L.NoEdu="Males.L_NoEdu" )
gather_table$`Literacy Level`<- recode(gather_table$`Literacy Level`,  Persons.L.NoEdu="Persons.L_NoEdu" )

#Write level 1 cleaning
write.csv(gather_table,file="Cleaned_Viz_project.csv")

The output of the following code looked like this :

Output R.JPG

The columns now are broken down to one categorical variable called "Literacy Level" and a numerical variable "Population"

Data Problem 4: "Literacy Level" is still not purely Literacy level"

Problem

The issue now is the with the "Literacy Level" column. A quick examination of the screenshot above will show that it also includes information of Persons, Male and Female. This information is delimited from the actual literacy level information by a "." character.

Solution

This could be easily solved with the Tidyverses separate function but it continued to throw and error. Hence the table was written to a csv file above and then imported into excel. In excel the text to column converter was used to separate the values into two distinct columns using the delimiter "." as the separation point.

Data Problem 5: The "Town Name" was not pure enough

Problem

This was a similar problem as above. Town Names were accompanied with additional information such as (M Corp. + OG) as seen above in Srinagar (M Corp.+ OG).

Solution

The same excel text to column function was used to separate the this column and extract only the town names. "(" character was used as a delimiter and the column containing (M Corp. + OG) values was deleted.

The resultant table looked like this:

OutPut Excel.JPG

There is another column called "Type level" that contains information about Persons, Male or Female and the "Town Name" contains only the town name.

Data Problem 6: Categories unclear under "Literacy Standard" variable

Problem

Here is an R summary of the data file shown above. It particularly shows the categories present in the "Literacy Standard" variable. This wasn't clean enough as there are two Below Primary values. There are two "illiterate" categories. This issue arose from the manual merging of the table in the very first step. Refer to Data Problem 1.

 
> summary(cleaned$Literacy.Standard)
   BelowPrim BelowPrimary  Diploma(NT)   Diploma(T)    Graduates   illiterate   Illiterate 
       29290        14645        43935        43935        43935        14645        29290 
     L_NoEdu     Literate            M            P       PreUni            S        Total 
       43935        43935        43935        43935        43935        43935        43935 
Unclassified 
       43935 

Solution

The solution involved importing it into JMP and recoding it using the recode function. The output is as shown in the summary as bellow.

Output JMP.JPG