Files
Incident_Report_Generator/pandas_helper.py
2025-11-05 12:58:07 -05:00

48 lines
1.6 KiB
Python

import pandas as pd
import xlsxwriter
# Just a few functions to help with Pandas
def set_data_frame_transposed(passed_data):
df_data = pd.DataFrame(data=passed_data)
df_data = df_data.T
(col, row) = df_data.shape
return (df_data, col, row)
def set_data_frame(passed_data):
df_data = pd.DataFrame(data=passed_data)
(col, row) = df_data.shape
return (df_data, col, row)
def make_bar_chart(workbook, title, series_length, series_height, start_row, start_col):
end_row = (series_height + start_row - 1)
chart = workbook.add_chart({'type': 'column'})
chart.set_title({'name': f'{title}'})
for series in range(series_length):
chart.add_series({
'name': ['Tables', start_row-1, start_col+series],
'categories': ['Tables', start_row, start_col-1, end_row, start_col-1],
'values': ['Tables', start_row, start_col+series, end_row, start_col+series],
})
chart.set_size({'x_scale': 1.5, 'y_scale': 1.5})
return chart
def make_pie_chart(workbook, title, series_length, series_height, start_row, start_col):
end_row = (series_height + start_row - 1)
chart = workbook.add_chart({'type': 'pie'})
chart.set_title({'name': f'{title}'})
for series in range(series_length):
chart.add_series({
'name': ['Tables', start_row-1, start_col+series],
'categories': ['Tables', start_row, start_col-1, end_row, start_col-1],
'values': ['Tables', start_row, start_col+series, end_row, start_col+series],
'data_labels': {'category': True},
})
chart.set_size({'x_scale': 1.5, 'y_scale': 1.5})
return chart