@@ -82,8 +82,31 @@ def addFunctionToData(row):
8282 res += 'male/'
8383 return res .strip ("/" )
8484
85- def parseData (file_name = "input.xlsx" ):
86- input_df = pd .read_excel (file_name )
85+ def parseData (file_name = "input.csv" ):
86+ try :
87+ print ("Trying to Read file: " + file_name )
88+ if file_name .endswith ('.csv' ):
89+ input_df = pd .read_csv (file_name )
90+ else :
91+ input_df = pd .read_excel (file_name )
92+ print ("Success!" )
93+ logging .info ("Success!" )
94+ except :
95+ print ("Cannot Read file: " + file_name )
96+ logging .info ("Cannot Read file: " + file_name )
97+
98+ try :
99+ print ("Try reading input.csv" )
100+ logging .info ("Try reading input.csv" )
101+ input_df = pd .read_csv ("input.csv" )
102+ print ("Success!" )
103+ logging .info ("Success!" )
104+ except Exception as e :
105+ logging .error ('Error at %s' , 'division' , exc_info = e )
106+
107+
108+ print ("Parsing the file..." )
109+ logging .info ("Parsing the file..." )
87110
88111 input_df ["name_length" ] = input_df .iloc [:,6 ].apply (lambda x : len (x ))
89112
@@ -128,29 +151,41 @@ def parseData(file_name="input.xlsx"):
128151
129152 return df , avg_df
130153
131- try :
132- print ("Parsing the input.xlsx file..." )
133- logging .info ("Parsing the input.xlsx file..." )
134- df , avg_df = parseData ()
135- print ("Success!" )
136- logging .info ("Success!" )
137- except Exception as e :
138- logging .error ('Error at %s' , 'division' , exc_info = e )
154+ def readInput ():
155+ res = input ("""
156+ Please enter your file name
157+ press enter directly to read input.csv
158+ (e.g. input.csv , Class1.xlsx)
159+ """ )
160+ if res == "" :
161+ res = "input.csv"
162+ return res
139163
140164try :
141- print ("Saving vehicleGroupData.csv file..." )
142- logging .info ("Saving vehicleGroupData.csv file..." )
143- df .to_csv ('vehicleGroupData.csv' , sep = ',' , encoding = 'utf-8' , index = False , header = False )
165+ res = readInput ()
166+ df , avg_df = parseData (res )
144167 print ("Success!" )
145168 logging .info ("Success!" )
146- except Exception as e :
147- logging .error ('Error at %s' , 'division' , exc_info = e )
148169
149- try :
150- print ("Saving AvgAnalysis.csv file..." )
151- logging .info ("Saving AvgAnalysis.csv file..." )
152- avg_df .iloc [0 :1 ,:].to_csv ('AvgAnalysis.csv' , sep = ',' , encoding = 'utf-8' , index = False , header = True )
153- print ("Success!" )
154- logging .info ("Success!" )
170+ try :
171+ print ("Saving vehicleGroupData.csv file..." )
172+ logging .info ("Saving vehicleGroupData.csv file..." )
173+ df .to_csv ('vehicleGroupData.csv' , sep = ',' , encoding = 'utf-8' , index = False , header = False )
174+ print ("Success!" )
175+ logging .info ("Success!" )
176+ except Exception as e :
177+ logging .error ('Error at %s' , 'division' , exc_info = e )
178+
179+ try :
180+ print ("Saving AvgAnalysis.csv file..." )
181+ logging .info ("Saving AvgAnalysis.csv file..." )
182+ avg_df .iloc [0 :1 ,:].to_csv ('AvgAnalysis.csv' , sep = ',' , encoding = 'utf-8' , index = False , header = True )
183+ print ("Success!" )
184+ logging .info ("Success!" )
185+ except Exception as e :
186+ logging .error ('Error at %s' , 'division' , exc_info = e )
187+
155188except Exception as e :
156189 logging .error ('Error at %s' , 'division' , exc_info = e )
190+
191+
0 commit comments