-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReport_parser_SA.py
51 lines (35 loc) · 1.43 KB
/
Report_parser_SA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 5 09:40:32 2023
@author: jbarker
"""
import config as cg
import pandas as pd
def read_SA_instrument_report(file_path):
try:
# Check the file extension to determine the engine
if file_path.endswith('.xlsx'):
engine = 'openpyxl'
else:
raise ValueError("Unsupported file format. Only .xlsx and .xls are supported.")
# Read the file using the determined engine
df = pd.read_excel(file_path, engine=engine)
# Remove rows with NaN in the first column
df = df.dropna(subset=[df.columns[0]])
return df
except Exception as e:
print("Error:", str(e))
return None
dict_measurements = {}
measurement_file = read_SA_instrument_report(cg.measurement_file_path)
Collection_occures = measurement_file[
measurement_file.columns[0]].str.contains('Collection',
case=True, na=False)
Collection_coords = list(Collection_occures[Collection_occures].index)
number_of_instruments = len(Collection_coords)
measurement_file2 = read_SA_instrument_report(cg.more_inst_file_path)
Collection_occures2 = measurement_file2[
measurement_file2.columns[0]].str.contains('Collection',
case=True, na=False)
Collection_coords2 = list(Collection_occures2[Collection_occures2].index)
number_of_instruments2 = len(Collection_coords2)