Last active
July 30, 2018 21:54
-
-
Save discarn8/2163cce9a4ce824d40522966d080f891 to your computer and use it in GitHub Desktop.
Python_graph_csv_files_in_directory_with_total_and_count
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
%matplotlib inline | |
import time | |
import os | |
import glob | |
import seaborn as sns | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pylab as plt | |
from matplotlib import rcParams | |
rcParams.update({'figure.autolayout': False}) | |
path = "C:/path/to/files/*.csv" | |
for fname in glob.glob(path): | |
temp1=os.path.basename(os.path.normpath(fname)) | |
dt=time.strftime('%Y%m%d', time.gmtime(os.path.getmtime(fname))) | |
filename=temp1.split('.')[0] | |
plt.figure(figsize=(14,10)) | |
plt.title(filename + ' ' + dt + '\nby Item' + '\n',fontsize = 16) | |
plt.xlabel('ITEM COUNT') | |
plt.ylabel('ITEM TYPE') | |
plt.gcf().subplots_adjust(bottom=0.34) | |
plt.style.use(['dark_background']) | |
plt.xticks(rotation=90) | |
items = pd.read_csv(fname, low_memory=False) | |
totl = len(items) | |
ax = sns.countplot( | |
items['Item Type'], | |
order=items['Item Type'].value_counts().index, | |
palette='Greens_r' | |
) | |
for p in ax.patches: | |
ax.annotate('{:.0f}'.format(p.get_height()), (p.get_x()+0.1, p.get_height()+10)) | |
plt.text(0.5,0.5, 'Item Count: ' + str(totl), | |
fontsize = 14, | |
color='white', | |
fontstyle='italic', | |
horizontalalignment='center', | |
verticalalignment='center', | |
transform = ax.transAxes) | |
sns.set_color_codes("pastel") | |
plt.savefig(filename + "_" + dt + ".png") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment