Chuyển đổi và phân tích dữ liệu phân loại

Phân tích dữ liệu khám phá trong Python

George Boorman

Curriculum Manager, DataCamp

Xem trước dữ liệu

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
Phân tích dữ liệu khám phá trong Python

Chức danh công việc

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
...
Phân tích dữ liệu khám phá trong Python

Chức danh công việc

print(salaries["Designation"].nunique())
50
Phân tích dữ liệu khám phá trong Python

Chức danh công việc

Biểu đồ cột hiển thị 5 vai trò dữ liệu phổ biến nhất - data scientist, data engineer, data analyst, machine learning engineer, và research scientist

Phân tích dữ liệu khám phá trong Python

Khai thác giá trị từ danh mục

  • Định dạng hiện tại hạn chế khả năng tạo insight

  • pandas.Series.str.contains()

    • Tìm một hoặc nhiều chuỗi trong cột
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
Phân tích dữ liệu khám phá trong Python

Tìm nhiều cụm trong chuỗi

  • Từ cần tìm: Machine Learning hoặc 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
Phân tích dữ liệu khám phá trong Python

Tìm nhiều cụm trong chuỗi

  • Từ cần tìm: Bất kỳ từ bắt đầu bằng 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
Phân tích dữ liệu khám phá trong Python

Tìm nhiều cụm trong chuỗi

job_categories = ["Data Science", "Data Analytics", 
                  "Data Engineering", "Machine Learning",
                  "Managerial", "Consultant"]
Phân tích dữ liệu khám phá trong Python

Tìm nhiều cụm trong chuỗi

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"
Phân tích dữ liệu khám phá trong Python

Tìm nhiều cụm trong chuỗi

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)) ]
Phân tích dữ liệu khám phá trong Python

Tạo cột phân loại

salaries["Job_Category"] = 


Phân tích dữ liệu khám phá trong Python

Tạo cột phân loại

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


Phân tích dữ liệu khám phá trong Python

Tạo cột phân loại

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

Phân tích dữ liệu khám phá trong Python

Tạo cột phân loại

salaries["Job_Category"] = np.select(conditions, 
                                     job_categories, 
                                     default="Other")
Phân tích dữ liệu khám phá trong Python

Xem trước nhóm công việc

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
Phân tích dữ liệu khám phá trong Python

Trực quan tần suất nhóm công việc

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

plt.show()

Biểu đồ cột số lượng việc theo nhóm

Phân tích dữ liệu khám phá trong Python

Ayo berlatih!

Phân tích dữ liệu khám phá trong Python

Preparing Video For Download...