Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

process_missing_data.py 882 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  1. from typing import List
  2. import numpy as np
  3. import pandas as pd
  4. from feature_engine.imputation import CategoricalImputer, DropMissingData
  5. # --------------------------------------
  6. # カテゴリー値の欠損を文字列"missing"に変換
  7. # --------------------------------------
  8. def categorical_imputer(
  9. df: pd.DataFrame,
  10. cat_col_names: List
  11. ) -> pd.DataFrame:
  12. imputer = CategoricalImputer(
  13. variables=cat_col_names
  14. )
  15. df = imputer.fit_transform(df)
  16. return df
  17. # --------------------------------------
  18. # 欠損のある行を全て削除
  19. # --------------------------------------
  20. def drop_missing_data(
  21. df: pd.DataFrame,
  22. ) -> pd.DataFrame:
  23. df_cols = df.columns.tolist()
  24. missing_data_imputer = DropMissingData(
  25. variables=df_cols
  26. )
  27. df = missing_data_imputer.fit_transform(df)
  28. return df
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...