Created
September 30, 2020 10:44
-
-
Save manmohan24nov/03ec6f6ab540bdff97ff84e0f2c73a60 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
# import the | |
import pandas as pd | |
from matplotlib import cm | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
import matplotlib.path as path | |
import matplotlib.ticker as ticker | |
import matplotlib.animation as animation | |
import pandas as pd | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
# Get numerical and categorical columns | |
total_columns = train.columns | |
num_col = train._get_numeric_data().columns | |
cat_col = list(set(total_columns)-set(num_col)) | |
# find categorical columns category and their counts | |
for i in cat_col: | |
print(i) | |
print(train[i].value_counts()) | |
# Plot graph for Item_Type category | |
index = np.arange(6) | |
fig, ax = plt.subplots(figsize=(15, 8)) | |
list1x = list(dict(train['Item_Type'].value_counts()).keys()) | |
list1y = list(train['Item_Type'].value_counts()) | |
ax.barh(list1x, list1y, alpha=0.7, | |
# width = 0.5, | |
color=cm.Blues([i / 0.00525 for i in [ 0.00208, 0.00235, 0.00281, 0.00317, 0.00362, 0.00371, 0.00525, 0.00679, 0.00761, 0.00833]]) | |
) | |
plt.rcParams.update({'font.size': 10}) | |
rects = ax.patches | |
for i, label in enumerate(list1y): | |
ax.text(label , i, str(label), size=10, ha='left', va='center') | |
ax.text(0, 1.02, 'Item_Type Food Category Count', transform=ax.transAxes, size=12, weight=600, color='#777777') | |
ax.xaxis.set_ticks_position('bottom') | |
ax.tick_params(axis='x', colors='black', labelsize=9) | |
ax.set_axisbelow(True) | |
ax.text(0, -0.1, 'Source: https://datahack.analyticsvidhya.com/contest/practice-problem-big-mart-sales-iii/#ProblemStatement', | |
transform=ax.transAxes, size=12, weight=600, color='#777777') | |
ax.spines['right'].set_visible(False) | |
ax.spines['top'].set_visible(False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment