<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Visualizing Categorical Data
Step1:  Observations
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import pandas as pd 
import collections 
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
# import seaborn as sns
# sns.set_style("whitegrid", {'axes.grid' : False})
train_categorical_iter=pd.read_csv("../data/train_categorical.csv",chunksize=100000, dtype=str,usecols=list(range(1,2141)))
train_categorical_data = collections.defaultdict(set)
for chunk in train_categorical_iter: 
    for col in chunk:
        train_categorical_data[col] = train_categorical_data[col].union(chunk[col][chunk[col].notnull()].unique())
print ("Number of Features " +str(len(train_categorical_data.keys())))
countEmpty=countSingle= countMultiple=0
for key in train_categorical_data.keys():
    if len(train_categorical_data[key])==0:
        countEmpty+=1
        continue
    if len(train_categorical_data[key])==1:
        countSingle+=1
        continue
    countMultiple+=1            
objects = ('Missing Value', 'Single Value', 'Multiple Values')
y_pos = np.arange(3)
 
plt.bar([0,1,2],[countEmpty, countSingle, countMultiple], align='center', color='r')
plt.xticks([0,1,2], objects)
plt.ylabel('Frequency')
plt.title('Features in Training Data (Categorical)')
plt.show()
Explanation: Visualizing Categorical Data
End of explanation
def plotFeatures(filename, xtitle, key):
    if "numeric" in filename:
        data = pd.read_csv(filename, nrows=1).drop(["Response", "Id"], axis=1).columns.values
    else:
        data = pd.read_csv(filename, nrows=1).drop(["Id"], axis=1).columns.values
    
        
    features = {}
    lines = set([dataPoint.split('_')[key] for dataPoint in data])
    
    for l in lines:
        features[l] = [item for item in data if l+'_' in item]
    xvalue = "Station Name"
    yvalue = "Number of Features"
    if key==0:
        xvalue = "Line Number"
    df = pd.DataFrame(list({int(key[1:]): len(features[key]) for
                         key in features.keys()}.items()),
                   columns=[xvalue, yvalue])
    stations_plot = df.plot(x=xvalue, y=yvalue, kind="bar",
                         title=xtitle,
                         color='blue')
    
        
plotFeatures("../data/train_numeric.csv", "Number of Numerical Features at a Station",1)
plotFeatures("../data/train_date.csv", "Number of Date Features at a Station",1)
plotFeatures("../data/train_categorical.csv", "Number of Categorical Features at a Station",1)
plotFeatures("../data/train_numeric.csv", "Number of Numerical Features at a Line",0)
plotFeatures("../data/train_date.csv", "Number of Date Features at a Line",0)
plotFeatures("../data/train_categorical.csv", "Number of Categorical Features at a Line",0)
Explanation: Observations:
Some categorical features have mutliple values corresponding to them.
Frequency of Features
End of explanation
<END_TASK>