डेटा टाइप constraints

R में डेटा क्लीनिंग

Maggie Matsui

Content Developer @ DataCamp

कोर्स रूपरेखा

मैग्नीफाइंग ग्लास वाला सर्वर और "गंदे डेटा का निदान"

R में डेटा क्लीनिंग

कोर्स रूपरेखा

बीटल बग वाला सर्वर और "गंदे डेटा के दुष्प्रभाव"

R में डेटा क्लीनिंग

कोर्स रूपरेखा

क्लीन डेटा के लिए झाड़ू और चमक वाला गोल डेटाबेस

R में डेटा क्लीनिंग

कोर्स रूपरेखा

गंदे डेटा का निदान, दुष्प्रभाव, और सफाई

अध्याय 1 - आम डेटा समस्याएँ

R में डेटा क्लीनिंग

हमें क्लीन डेटा क्यों चाहिए?

 

डेटा साइंस वर्कफ़्लो: डेटा एक्सेस करें, डेटा एक्सप्लोर और प्रोसेस करें, इनसाइट्स निकालें, इनसाइट्स रिपोर्ट करें

R में डेटा क्लीनिंग

हमें क्लीन डेटा क्यों चाहिए?

 

मानवीय और तकनीकी त्रुटि

R में डेटा क्लीनिंग

हमें क्लीन डेटा क्यों चाहिए?

 

त्रुटियाँ वर्कफ़्लो में फैलती हैं

R में डेटा क्लीनिंग

डेटा टाइप constraints

डेटा टाइप उदाहरण
टेक्स्ट पहला नाम, अंतिम नाम, पता, ...
इंटीजर सब्सक्राइबर काउंट, # प्रोडक्ट्स बेचे, ...
डेसिमल तापमान, एक्सचेंज रेट, ...
बाइनरी शादीशुदा है, नया कस्टमर, हाँ/नहीं, ...
कैटेगरी वैवाहिक स्थिति, रंग, ...
डेट ऑर्डर डेट, जन्म तिथि, ...
R डेटा टाइप
character
integer
numeric
logical
factor
Date
R में डेटा क्लीनिंग

डेटा टाइप्स पर एक नज़र

sales <- read.csv("sales.csv")
head(sales)
  order_id revenue quantity
1     7432   5,454      494
2     7808   5,668      334
3     4893   4,062      259
4     6107   3,936       15
5     7661   1,067      307
6     5908   6,635      235
library(dplyr)
glimpse(sales)
Observations: 100
Variables: 3
$ order_id <dbl> 7432, 7808, ...
$ revenue  <chr> "$5454", "$5668", ...
$ quantity <dbl> 494, 334, ...
R में डेटा क्लीनिंग

डेटा टाइप्स जाँचना

is.numeric(sales$revenue)
FALSE
library(assertive)
assert_is_numeric(sales$revenue)
Error: is_numeric : sales$revenue is not of class 'numeric'; it has class 'character'.
assert_is_numeric(sales$quantity)


R में डेटा क्लीनिंग

डेटा टाइप्स जाँचना

Logical checking - TRUE/FALSE देता है

  • is.character()
  • is.numeric()
  • is.logical()
  • is.factor()
  • is.Date()
  • ...

assertive checking - FALSE होने पर error

  • assert_is_character()
  • assert_is_numeric()
  • assert_is_logical()
  • assert_is_factor()
  • assert_is_date()
  • ...
R में डेटा क्लीनिंग

डेटा टाइप मायने क्यों रखता है?

class(sales$revenue)
"character"
mean(sales$revenue)
NA
Warning message:
In mean.default(sales$revenue) :
  argument is not numeric or logical: returning NA
R में डेटा क्लीनिंग

कॉमा समस्याएँ

sales$revenue
"5,454" "5,668" "4,062" "3,936" "1,067" ...

R में डेटा क्लीनिंग

कैरेक्टर से नंबर

library(stringr)
revenue_trimmed = str_remove(sales$revenue, ",")

revenue_trimmed
"5454" "5668" "4062" "3936" "1067" ...
as.numeric(revenue_trimmed)
5454 5668 4062 3936 1067 ...
R में डेटा क्लीनिंग

सब कुछ साथ मिलाकर

sales %>%
  mutate(revenue_usd = as.numeric(str_remove(revenue, ",")))
# A tibble: 100 x 4
   order_id revenue quantity revenue_usd
      <dbl> <chr>      <dbl>       <dbl>
 1     7432 5,454        494        5454
 2     7808 5,668        334        5668
 3     4893 4,062        259        4062
 4     6107 3,936         15        3936
 5     7661 1,067        307        1067
# ... with 95 more rows
R में डेटा क्लीनिंग

वही फंक्शन, अलग नतीजे

mean(sales$revenue)
NA
Warning message:
In mean.default(sales$revenue) :
  argument is not numeric or logical: returning NA
mean(sales$revenue_usd)
5361.4
R में डेटा क्लीनिंग

डेटा टाइप्स कन्वर्ट करना

  • as.character()
  • as.numeric()
  • as.logical()
  • as.factor()
  • as.Date()
  • ...
R में डेटा क्लीनिंग

ध्यान दें: factor से numeric

product_type
1000 1000 3000 2000 3000
Levels: 1000 2000 3000
class(product_type)
"factor"
as.numeric(product_type)
1 1 3 2 3
as.numeric(as.character(product_type))
1000 1000 3000 2000 3000
R में डेटा क्लीनिंग

अभ्यास करते हैं!

R में डेटा क्लीनिंग

Preparing Video For Download...