forked from oceanobservatories/preload-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_1100.py
executable file
·33 lines (24 loc) · 867 Bytes
/
parse_1100.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
#!/usr/bin/env python
import pandas as pd
def get_depth_data(df):
refdes_column = [c for c in df.columns if 'ooi' in c.lower()]
depth_column = [c for c in df.columns if 'depth' in c.lower()]
if len(refdes_column) == 1 and len(depth_column) == 1:
df = df[refdes_column + depth_column]
df = df.dropna()
return df.rename(index=str, columns={refdes_column[0]: 'designator', depth_column[0]: 'depth'})
def parse_file(filepath, outpath):
frames = []
sheets = pd.read_excel(filepath, sheetname=None)
for sheet in sheets:
df = get_depth_data(sheets[sheet])
if df is not None:
frames.append(df)
df = pd.concat(frames)
df = df.sort_values('designator')
df.to_csv(outpath, index=False)
def main():
import sys
parse_file(*sys.argv[1:3])
if __name__ == '__main__':
main()