Skip to content

Update ggplot_plots.py #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions csv/supplier_data_two_commas_added_in_excel.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Supplier Name,Invoice Number,Part Number,Cost,Purchase Date
Supplier X,001-1001,2341,$500.00 ,1/20/14
Supplier X,001-1001,2341,$500.00 ,1/20/14
Supplier X,001-1001,5467,$750.00 ,1/20/14
Supplier X,001-1001,5467,$750.00 ,1/20/14
Supplier Y,50-9501,7009,$250.00 ,1/30/14
Supplier Y,50-9501,7009,$250.00 ,1/30/14
Supplier Y,50-9505,6650,$125.00 ,2002-03-14
Supplier Y,50-9505,6650,$125.00 ,2002-03-14
Supplier Z,920-4803,3321,$615.00 ,2002-03-14
Supplier Z,920-4804,3321,$615.00 ,2002-10-14
Supplier Z,920-4805,3321,"$6,015.00 ",2/17/14
Supplier Z,920-4806,3321,"$1,006,015.00 ",2/24/14
14 changes: 7 additions & 7 deletions excel/pandas_sum_average_multiple_workbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
worksheets_data_frame = None
workbook_data_frame = None
for worksheet_name, data in all_worksheets.items():
total_sales = pd.DataFrame([float(str(value).strip('$').replace(',','')) for value in data.ix[:, 'Sale Amount']]).sum()
total_sales = pd.DataFrame([float(str(value).strip('$').replace(',','')) for value in data.ix[:, 'Sale Amount']]).sum().iloc[0]
number_of_sales = len(data.loc[:, 'Sale Amount'])
average_sales = pd.DataFrame(total_sales / number_of_sales)
average_sales = total_sales / number_of_sales

workbook_total_sales.append(total_sales)
workbook_number_of_sales.append(number_of_sales)
Expand All @@ -29,23 +29,23 @@
'worksheet_total': total_sales,
'worksheet_average': average_sales}

worksheet_data_frames.append(pd.DataFrame(data, columns=['workbook', 'worksheet', 'worksheet_total', 'worksheet_average']))
worksheet_data_frames.append(pd.DataFrame(data, columns=['workbook', 'worksheet', 'worksheet_total', 'worksheet_average'], index=[0]))
worksheets_data_frame = pd.concat(worksheet_data_frames, axis=0, ignore_index=True)

workbook_total = pd.DataFrame(workbook_total_sales).sum()
workbook_total = pd.DataFrame(workbook_total_sales).sum().iloc[0]
workbook_total_number_of_sales = pd.DataFrame(workbook_number_of_sales).sum()
workbook_average = pd.DataFrame(workbook_total / workbook_total_number_of_sales)
workbook_average = workbook_total / workbook_total_number_of_sales

workbook_stats = {'workbook': os.path.basename(workbook),
'workbook_total': workbook_total,
'workbook_average': workbook_average}

workbook_stats = pd.DataFrame(workbook_stats, columns=['workbook', 'workbook_total', 'workbook_average'])
workbook_stats = pd.DataFrame(workbook_stats, columns=['workbook', 'workbook_total', 'workbook_average'], index=[0])
workbook_data_frame = pd.merge(worksheets_data_frame, workbook_stats, on='workbook', how='left')
data_frames.append(workbook_data_frame)

all_data_concatenated = pd.concat(data_frames, axis=0, ignore_index=True)

writer = pd.ExcelWriter(output_file)
all_data_concatenated.to_excel(writer, sheet_name='sums_and_averages', index=False)
writer.save()
writer.save()
2 changes: 1 addition & 1 deletion plots/ggplot_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
theme_gray()
print(plt3)

ggsave(plt3, "ggplot_plots.png")
plt3.save("ggplot_plots.png")