Input in “TableHeaderData” file output from the Horiba Duetta “Kinetic Spectra” data acquisition mode. Cleans up data file for easy data analysis. Outputs spreadsheet in same directory as python script. 

# -*- coding: utf-8 -*-
Created on Mon Jun 14 22:13:18 2021

@author: Cyrus Picou Jr.
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QFileDialog, QLabel,QPushButton, QVBoxLayout)
from PyQt5.QtWidgets import QLineEdit
import pandas as pd

class DialogApp(QWidget):
    def __init__(self):
        self.button1 = QPushButton('Load and Fix Data') #makes pushbutton
        self.line1 = QLineEdit()#makes line to add time increment for spectra w/ s units
        self.label1 = QLabel('Time Increment (s)')#adds label for first line
        self.line2 = QLineEdit()#line for new file name
        self.label2 = QLabel('New File Name')#label for new line
        #this section makes the layout of the GUI using vertical box layout
        layout = QVBoxLayout()

        #have to put button clicked event after layout stuff, now it works
        self.button1.clicked.connect(self.buttonClicked)#controls the first button click

    def buttonClicked(self):
        file_name, _ = QFileDialog.getOpenFileName()
        ##need the comma and underscore after file_name, returns filename as str
        file = pd.read_csv(file_name,sep = "\t", header = None)
        file2 = file.copy()
        c_path = 4#the following section takes care of deleting columns and adding the time row
        t_path = 2
        t_par = 0
        t_int = pd.to_numeric(self.line1.text(), downcast = "integer")
        while c_path <= len(file.columns):
            file2 = file2.drop(c_path - 1, axis = 1)
            c_path += 2
            file2.loc[11,t_path] = t_par
            t_par += t_int
            t_path += 2
        #this code takes care of changing all of the data to float datatype
        row = 12
        r_sum = len(file2.index) - 1
        while row <= r_sum:
            file2.loc[row] = pd.to_numeric(file2.loc[row], downcast = "float")
            row += 1
        ext = '.xlsx'
        fname = self.line2.text() + ext#adds excel file type extension to the file name
        file2.to_excel(fname)#saves dataframe as an excel file

if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = DialogApp()