Last active
January 19, 2022 10:13
-
-
Save sh16ma/1e2a3c14ae824ae2a22f67370bc809d8 to your computer and use it in GitHub Desktop.
#🐍 #Python #EDA #NaN #ランキング形式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nan_rank(df, usabilty=20): | |
""" | |
df : データフレーム | |
usabilty : データの割合に応じての足切りライン | |
""" | |
nan = df.isnull().sum().reset_index() | |
nan.columns = ["name", "count"] | |
nan["ratio"] = (nan["count"] / df.shape[0])*100 | |
nan["usabilty"] = np.where(nan["ratio"] > usabilty, "Discard", "Keep") | |
nan = nan[nan["count"] > 0].sort_values(by="ratio") | |
plt.figure(figsize=(15, 6)) | |
sns.barplot(x=nan["name"], y=nan["ratio"]) | |
plt.xticks(rotation=90) #90°傾け | |
plt.title("Feature containing NaN.") | |
plt.show() | |
return nan |
Author
sh16ma
commented
Feb 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment