Below shown is the categorical data detail for the bar chart, which is from a specific DataFrame
column i.e. coast
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
IN: data['coast'].dtypes
OUT:
CategoricalDtype(categories=[0, 1], ordered=False)
IN: data['coast'].value_counts()
OUT:
0 21450
1 163
Name: coast, dtype: int64
Shown below syntax is the defined function used, to get the bar chart.
def code(c):
plt.rc('figure', figsize=(10, 5))
ax = c.value_counts().plot(kind='bar')
for value in ax:
height = value.get_height()
plt.text(value.get_x() + value.get_width()/2.,
1.002*height,'%d' % int(height), ha='center', va='bottom')
However, the bar chart does appears without the values on the bar which is shown below.
IN: code(data['coast'])
OUT:
But the below error message appears
---------------------------------------------------------------------------
TypeError: 'AxesSubplot' object is not iterable
---------------------------------------------------------------------------
How could I resolve the above error to get the below bar chart.