การแปลงและวิเคราะห์ข้อมูลเชิงหมวดหมู่

การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

George Boorman

Curriculum Manager, DataCamp

ดูตัวอย่างข้อมูล

print(salaries.select_dtypes("object").head())
  Designation                 Experience    Employment_Status    Employee_Location    Company_Size
0 Data Scientist              Mid           FT                   DE                   L
1 Machine Learning Scientist  Senior        FT                   JP                   S
2 Big Data Engineer           Senior        FT                   GB                   M
3 Product Data Analyst        Mid           FT                   HN                   S
4 Machine Learning Engineer   Senior        FT                   US                   L
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ตำแหน่งงาน

print(salaries["Designation"].value_counts())
Data Scientist                              143
Data Engineer                               132
Data Analyst                                 97
Machine Learning Engineer                    41
Research Scientist                           16
Data Science Manager                         12
Data Architect                               11
Big Data Engineer                             8
Machine Learning Scientist                    8
...
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ตำแหน่งงาน

print(salaries["Designation"].nunique())
50
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ตำแหน่งงาน

กราฟแท่งแสดงตำแหน่งงานด้านข้อมูลที่ได้รับความนิยมสูงสุด 5 อันดับ ได้แก่ Data Scientist, Data Engineer, Data Analyst, Machine Learning Engineer และ Research Scientist

การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ดึงคุณค่าจากหมวดหมู่

  • รูปแบบปัจจุบันจำกัดความสามารถในการสร้าง insight

  • pandas.Series.str.contains()

    • ค้นหาสตริงหนึ่งหรือหลายสตริงในคอลัมน์
salaries["Designation"].str.contains("Scientist")
0       True
1       True
2      False
3      False
       ...  
604    False
605    False
606     True
Name: Designation, Length: 607, dtype: bool
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ค้นหาหลายวลีในสตริง

  • คำที่ต้องการ: Machine Learning หรือ AI
salaries["Designation"].str.contains("Machine Learning|AI")
0      False
1       True
2      False
3      False
       ...  
604    False
605    False
606     True
Name: Designation, Length: 607, dtype: bool
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ค้นหาหลายวลีในสตริง

  • คำที่ต้องการ: คำที่ขึ้นต้นด้วย Data
salaries["Designation"].str.contains("^Data")
0       True
1      False
2      False
3      False
       ...  
604     True
605     True
606    False
Name: Designation, Length: 607, dtype: bool
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ค้นหาหลายวลีในสตริง

job_categories = ["Data Science", "Data Analytics", 
                  "Data Engineering", "Machine Learning",
                  "Managerial", "Consultant"]
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ค้นหาหลายวลีในสตริง

data_science = "Data Scientist|NLP"

data_analyst = "Analyst|Analytics"
data_engineer = "Data Engineer|ETL|Architect|Infrastructure"
ml_engineer = "Machine Learning|ML|Big Data|AI"
manager = "Manager|Head|Director|Lead|Principal|Staff"
consultant = "Consultant|Freelance"
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ค้นหาหลายวลีในสตริง

conditions = [
    (salaries["Designation"].str.contains(data_science)),

(salaries["Designation"].str.contains(data_analyst)),
(salaries["Designation"].str.contains(data_engineer)),
(salaries["Designation"].str.contains(ml_engineer)),
(salaries["Designation"].str.contains(manager)),
(salaries["Designation"].str.contains(consultant)) ]
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

สร้างคอลัมน์หมวดหมู่

salaries["Job_Category"] = 


การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

สร้างคอลัมน์หมวดหมู่

salaries["Job_Category"] = np.select(conditions, 


การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

สร้างคอลัมน์หมวดหมู่

salaries["Job_Category"] = np.select(conditions, 
                                     job_categories, 

การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

สร้างคอลัมน์หมวดหมู่

salaries["Job_Category"] = np.select(conditions, 
                                     job_categories, 
                                     default="Other")
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

ดูตัวอย่างหมวดหมู่งาน

print(salaries[["Designation", "Job_Category"]].head())
                  Designation      Job_Category
0              Data Scientist      Data Science
1  Machine Learning Scientist  Machine Learning
2           Big Data Engineer  Data Engineering
3        Product Data Analyst    Data Analytics
4   Machine Learning Engineer  Machine Learning
การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

แสดงความถี่ของหมวดหมู่งาน

sns.countplot(data=salaries, x="Job_Category")

plt.show()

กราฟแท่งแสดงจำนวนงานแต่ละหมวดหมู่

การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

มาฝึกกันเถอะ!

การวิเคราะห์ข้อมูลเชิงสำรวจด้วย Python

Preparing Video For Download...