import pandas as pd # file_path = 'C:/GIT/SingleStation/ini/Protocol2' # df = pd.read_xml(file_path) def prtc2excel(*arg): file_path = arg[0] values = [] lens = [] state = 0 value = '' preFix = '' postFix = '' with open(file_path) as fp: for i, line in enumerate(fp): if '' in line: lens.append(line[line.find('')+len(''):line.rfind('')]) elif preFix in line and state == 0: state = 1 value = value + line if postFix in line: state = 0 values.append(value) value = '' elif state == 1: value = value + line if postFix in line: state = 0 values.append(value) value = '' arr = [] k = 0 for i in range(int(lens[0])): arr.append([]) for j in range(int(lens[1])): value = values[k] arr[i].append(value[value.find(preFix)+len(preFix):value.rfind(postFix)]) k += 1 # for value in values: # print(value[value.find(preFix)+len(preFix):value.rfind(postFix)]) # zip(*arr) invArr = [['0' for x in range(int(lens[0]))] for y in range(int(lens[1]))] for j in range(int(lens[0])): for i in range(int(lens[1])): invArr[i][j] = arr [j][i] df = pd.DataFrame(invArr).T df.to_excel(excel_writer = file_path + '.xlsx', index=False, header=False)