import pandas as pd
from openpyxl import Workbook, load_workbook
from openpyxl.styles import Alignment
col_in = [‘stc_ori_inputs’, ‘stc_input_dtypes’, ‘dyn_input_ori_formats’]
col_out = [‘stc_ori_outputs’, ‘stc_output_dtypes’, ‘output_ori_formats’]
col_dyn = [‘dyn_inputs’, ‘dyn_dtypes’, ‘dyn_input_ori_formats’]
var_in = [‘x’, ‘sum’, ‘squre_sum’, ‘scale’, ‘offset’, ‘mean’, ‘variance’]
var_out = [‘y’, ‘mean_out’, ‘variance_out’, ‘bacth_mean’, ‘batch_variance’]
var_dyn = [‘dyn’, ‘dyn_sum’, ‘dyn_squre_sum’, ‘dyn_scale’, ‘dyn_offset’, ‘dyn_mean’, ‘dyn_variance’]
suffix = [’_stc_shape’, ‘_dtype’, ‘_format’]
train_df = pd.read_csv(r’train_simple.csv’)
train_header = train_df.columns.tolist()
res_header = [‘Etrainupdate’]
res_header.extend([i + j for i in var_in for j in suffix])
res_header.append(‘is_enable’)
res_header.extend([i + j for i in var_out for j in suffix])
res_header.extend([i + j for i in var_dyn for j in suffix])
res_df = pd.DataFrame(columns = res_header)
two_df = pd.concat([train_df, res_df], axis = 1)
def extract_to_result(col_names, var_names):
sdf = []
for col in col_names:
sdf.append(eval(row[col]))# sdf = [shapes, dtypes, formats]
for i in range(len(sdf)):
if type(sdf[i]) == str:
sdf[i] = sdf[i].split(’ ')
# print(sdf)
for i in range(len(sdf[0])):
for j in range(len(sdf)):
value = sdf[j][i % len(sdf[j])]
if type(value) == tuple:
value = ‘,’.join(map(str, value)) + ‘,’
row[var_names[i % len(var_names)] + suffix[j % len(suffix)]] = value
for index, row in two_df.iterrows():
extract_to_result(col_in, var_in)
extract_to_result(col_out, var_out)
extract_to_result(col_dyn, var_dyn)
two_df.drop(labels=train_header, axis=1, inplace=True)
two_df.to_excel(‘result_simple.xlsx’, index=False)