Created
January 22, 2024 06:39
-
-
Save smzn/8d28fb32dfc37e96b79724642ae3a807 to your computer and use it in GitHub Desktop.
箱ひげ図
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
# Identifying binary columns in the dataset | |
binary_columns = [col for col in data.columns if is_binary(data[col])] | |
# Creating combinations of binary and non-binary numeric columns for box plots | |
binary_non_binary_combinations = list(itertools.product(binary_columns, non_binary_numeric_columns)) | |
# Setting up the plotting grid for these combinations | |
n_plots = len(binary_non_binary_combinations) | |
n_cols = 3 # Number of columns per row | |
n_rows = (n_plots + n_cols - 1) // n_cols # Calculating the required number of rows | |
fig, axes = plt.subplots(n_rows, n_cols, figsize=(15, 5 * n_rows)) # Adjusting the figure size | |
axes = axes.flatten() | |
# Creating box plots for each combination | |
for i, (binary_col, numeric_col) in enumerate(binary_non_binary_combinations): | |
sns.boxplot(x=binary_col, y=numeric_col, data=data, ax=axes[i]) | |
axes[i].set_title(f'{numeric_col} by {binary_col}') | |
# Hiding any unused axes | |
for j in range(i + 1, len(axes)): | |
axes[j].set_visible(False) | |
plt.tight_layout() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment