In [1]:
import pandas as pd
import arcpy
import os
import sys
import numpy as np
arcpy.env.overwriteOutput = True

In [15]:
xlfile = "H:/GWP/Wetland/WaterMonitoring/PiezometerData/PiezometersCorrected_2015_1.xlsx"

In [16]:
xl = pd.ExcelFile(xlfile)

In [17]:
sde_conn = "C:/Users/{:}/AppData/Roaming/ESRI/Desktop10.5/ArcCatalog/UGS_SDE.sde".format(os.environ.get('USERNAME'))
arcpy.env.workspace = sde_conn

In [18]:
def add_data(df):
    gw_reading_table="UGGP.UGGPADMIN.UGS_GW_reading"
    
    read_descr = arcpy.Describe(gw_reading_table)
    fieldnames = []
    for field in read_descr.fields:
        fieldnames.append(field.name)
    fieldnames.remove('OBJECTID')
    fieldnames.remove('DELTALEVEL')
    table_names = df.columns
    
    for name in fieldnames:
        if name not in table_names:
            fieldnames.remove(name)

            
    if len(fieldnames) > 0:
        subset = df[fieldnames]
        rowlist = subset.values.tolist()

        arcpy.env.overwriteOutput = True
        edit = arcpy.da.Editor(arcpy.env.workspace)
        edit.startEditing(False, False)
        edit.startOperation()

        cursor = arcpy.da.InsertCursor(gw_reading_table, fieldnames)
        for j in range(len(rowlist)):
            cursor.insertRow(rowlist[j])

        del cursor
        edit.stopOperation()
        edit.stopEditing(True)
        print('Well {:} imported!'.format(df['LOCATIONID'].values[-1]))
    else:
        print('No data imported!')

In [19]:
xl.sheet_names


Out[19]:
['Combined',
 'LastEntryCompile',
 'Metadata',
 'FieldData',
 'PreviousDownloadLastLine',
 'BARO1',
 'BARO2',
 'BARO3',
 'BARO14',
 '1001',
 '1002',
 '1003',
 '1004',
 '1005',
 '1006',
 '1007',
 '1008',
 '1009',
 '1010',
 '1011',
 '1012',
 '1013',
 '1014',
 '1015',
 '1016',
 '1018',
 '1019',
 '1020',
 '1021',
 '1022',
 '1023',
 '1024',
 '1025',
 '1026',
 '1028',
 '1029',
 '1030',
 '1031',
 '1033',
 '1035',
 '1036',
 '1037',
 '1038',
 '1039',
 '1040',
 '1041',
 '1042',
 '1043',
 '1044',
 '1045',
 '1046',
 '1047',
 '1049',
 '1051',
 '1052',
 '1053',
 '1054',
 '1055',
 '1056',
 '1057',
 '1060',
 '1063',
 '1065',
 '1067',
 '1068',
 '1069',
 '1070',
 '1072',
 '1073',
 '1075',
 '1076',
 '1077',
 '1078',
 '1079',
 '1080',
 '1081',
 '1090',
 '1091',
 '1092',
 '1093',
 '1094',
 '1095',
 '1096',
 '1097',
 '1098',
 '2001',
 '2002',
 '2003',
 '3001',
 '3002',
 '3003']

In [14]:
sheet = '1005'

cols = ['READINGDATE','MEASUREDLEVEL','TEMP','BP','MEASUREDDTW','DRIFTCORRECTION','WATERELEVATION','DTWBELOWGROUNDSURFACE']
test = xl.parse(sheet, parse_cols=("A,B,C,D,E,L,M,N"), skiprows=1,header=None)
test.columns = cols
test
test['TAPE'] = 0
test['LOCATIONID'] = int(sheet)
test


Out[14]:
READINGDATE MEASUREDLEVEL TEMP BP MEASUREDDTW DRIFTCORRECTION WATERELEVATION DTWBELOWGROUNDSURFACE TAPE LOCATIONID
0 2015-05-20 17:00:59 7.519 9.5 2.7003 4.8187 -0.000014 4759.748140 -0.846219 0 1005
1 2015-05-20 18:00:59 7.464 9.5 2.6810 4.7830 -0.000028 4759.712454 -0.881905 0 1005
2 2015-05-20 19:00:59 7.446 9.5 2.6717 4.7743 -0.000042 4759.703768 -0.890591 0 1005
3 2015-05-20 20:00:59 7.455 9.5 2.6729 4.7821 -0.000056 4759.711582 -0.882777 0 1005
4 2015-05-20 21:00:59 7.491 9.5 2.6960 4.7950 -0.000070 4759.724496 -0.869863 0 1005
5 2015-05-20 22:00:59 7.519 9.5 2.7270 4.7920 -0.000084 4759.721510 -0.872849 0 1005
6 2015-05-20 23:00:59 7.666 9.5 2.7360 4.9300 -0.000098 4759.859524 -0.734835 0 1005
7 2015-05-21 00:00:59 7.721 9.5 2.7413 4.9797 -0.000112 4759.909237 -0.685121 0 1005
8 2015-05-21 01:00:59 7.694 9.5 2.7380 4.9560 -0.000126 4759.885551 -0.708808 0 1005
9 2015-05-21 02:00:59 7.675 9.5 2.7413 4.9337 -0.000140 4759.863265 -0.731094 0 1005
10 2015-05-21 03:00:59 7.661 9.5 2.7449 4.9161 -0.000154 4759.845679 -0.748680 0 1005
11 2015-05-21 04:00:59 7.652 9.5 2.7451 4.9069 -0.000168 4759.836493 -0.757866 0 1005
12 2015-05-21 05:00:59 7.643 9.5 2.7436 4.8994 -0.000182 4759.829007 -0.765352 0 1005
13 2015-05-21 06:00:59 7.638 9.5 2.7426 4.8954 -0.000196 4759.825021 -0.769338 0 1005
14 2015-05-21 07:00:59 7.643 9.5 2.7474 4.8956 -0.000210 4759.825235 -0.769124 0 1005
15 2015-05-21 08:00:59 7.643 9.5 2.7487 4.8943 -0.000224 4759.823949 -0.770410 0 1005
16 2015-05-21 09:00:59 7.638 9.5 2.7424 4.8956 -0.000238 4759.825263 -0.769096 0 1005
17 2015-05-21 10:00:59 7.615 9.5 2.7288 4.8862 -0.000252 4759.815877 -0.778482 0 1005
18 2015-05-21 11:00:59 7.588 9.5 2.7190 4.8690 -0.000266 4759.798691 -0.795668 0 1005
19 2015-05-21 12:00:59 7.551 9.5 2.7122 4.8388 -0.000280 4759.768505 -0.825854 0 1005
20 2015-05-21 13:00:59 7.496 9.5 2.6823 4.8137 -0.000294 4759.743419 -0.850940 0 1005
21 2015-05-21 14:00:59 7.482 9.5 2.6865 4.7955 -0.000308 4759.725233 -0.869126 0 1005
22 2015-05-21 15:00:59 7.446 9.5 2.6445 4.8015 -0.000322 4759.731247 -0.863112 0 1005
23 2015-05-21 16:00:59 7.423 9.5 2.6657 4.7573 -0.000336 4759.687061 -0.907298 0 1005
24 2015-05-21 17:00:59 7.579 9.5 2.6473 4.9317 -0.000350 4759.861475 -0.732884 0 1005
25 2015-05-21 18:00:59 7.533 9.5 2.6236 4.9094 -0.000363 4759.839189 -0.755170 0 1005
26 2015-05-21 19:00:59 7.478 9.5 2.6070 4.8710 -0.000377 4759.800803 -0.793556 0 1005
27 2015-05-21 20:00:59 7.505 9.5 2.6347 4.8703 -0.000391 4759.800117 -0.794242 0 1005
28 2015-05-21 21:00:59 7.524 9.5 2.6609 4.8631 -0.000405 4759.792931 -0.801428 0 1005
29 2015-05-21 22:00:59 7.524 9.5 2.6528 4.8712 -0.000419 4759.801045 -0.793314 0 1005
... ... ... ... ... ... ... ... ... ... ...
3810 2015-10-26 11:00:59 7.115 14.3 2.8719 4.2431 -0.053281 4759.225806 -1.368553 0 1005
3811 2015-10-26 12:00:59 7.087 14.3 2.8500 4.2370 -0.053295 4759.219720 -1.374639 0 1005
3812 2015-10-26 13:00:59 7.055 14.3 2.8324 4.2226 -0.053309 4759.205334 -1.389025 0 1005
3813 2015-10-26 14:00:59 7.018 14.3 2.8047 4.2133 -0.053323 4759.196048 -1.398311 0 1005
3814 2015-10-26 15:00:59 6.986 14.3 2.7841 4.2019 -0.053337 4759.184662 -1.409697 0 1005
3815 2015-10-26 16:00:59 6.963 14.3 2.7616 4.2014 -0.053350 4759.184176 -1.410183 0 1005
3816 2015-10-26 17:00:59 6.949 14.3 2.7537 4.1953 -0.053364 4759.178090 -1.416269 0 1005
3817 2015-10-26 18:00:59 6.945 14.3 2.7467 4.1983 -0.053378 4759.181104 -1.413255 0 1005
3818 2015-10-26 19:00:59 6.945 14.3 2.7374 4.2076 -0.053392 4759.190418 -1.403941 0 1005
3819 2015-10-26 20:00:59 6.959 14.3 2.7475 4.2115 -0.053406 4759.194332 -1.400027 0 1005
3820 2015-10-26 21:00:59 6.977 14.3 2.7618 4.2152 -0.053420 4759.198046 -1.396313 0 1005
3821 2015-10-26 22:00:59 6.982 14.2 2.7662 4.2158 -0.053434 4759.198660 -1.395699 0 1005
3822 2015-10-26 23:00:59 6.995 14.2 2.7836 4.2114 -0.053448 4759.194274 -1.400085 0 1005
3823 2015-10-27 00:00:59 7.000 14.2 2.7836 4.2164 -0.053462 4759.199288 -1.395071 0 1005
3824 2015-10-27 01:00:59 7.005 14.2 2.7875 4.2175 -0.053476 4759.200402 -1.393957 0 1005
3825 2015-10-27 02:00:59 7.014 14.2 2.8008 4.2132 -0.053490 4759.196116 -1.398243 0 1005
3826 2015-10-27 03:00:59 7.014 14.2 2.7937 4.2203 -0.053504 4759.203230 -1.391129 0 1005
3827 2015-10-27 04:00:59 7.014 14.2 2.8002 4.2138 -0.053518 4759.196744 -1.397615 0 1005
3828 2015-10-27 05:00:59 7.037 14.2 2.8115 4.2255 -0.053532 4759.208458 -1.385901 0 1005
3829 2015-10-27 06:00:59 7.037 14.2 2.8183 4.2187 -0.053546 4759.201672 -1.392687 0 1005
3830 2015-10-27 07:00:59 7.051 14.2 2.8274 4.2236 -0.053560 4759.206586 -1.387773 0 1005
3831 2015-10-27 08:00:59 7.051 14.2 2.8306 4.2204 -0.053574 4759.203400 -1.390959 0 1005
3832 2015-10-27 09:00:59 7.069 14.2 2.8581 4.2109 -0.053588 4759.193914 -1.400445 0 1005
3833 2015-10-27 10:00:59 7.096 14.2 2.8739 4.2221 -0.053602 4759.205128 -1.389231 0 1005
3834 2015-10-27 11:00:59 7.101 14.2 2.8779 4.2231 -0.053616 4759.206142 -1.388217 0 1005
3835 2015-10-27 12:00:59 7.106 14.2 2.8885 4.2175 -0.053630 4759.200556 -1.393803 0 1005
3836 2015-10-27 13:00:59 7.119 14.2 2.9051 4.2139 -0.053644 4759.196970 -1.397389 0 1005
3837 2015-10-27 14:00:59 7.106 14.2 2.9073 4.1987 -0.053658 4759.181784 -1.412575 0 1005
3838 2015-10-27 15:00:59 7.092 14.2 2.8971 4.1949 -0.053672 4759.177998 -1.416361 0 1005
3839 2015-10-27 16:00:59 7.092 14.1 2.8916 4.2004 -0.053700 4759.183526 -1.410833 0 1005

3840 rows × 10 columns


In [ ]:
if test.loc[test.last_valid_index(),'DRIFTCORRECTION'] < 0.3:
    add_data(test)
else:
    print('Well {:} drift too high'.format(test['LOCATIONID'].values[-1]))

In [7]:
xldict = {}
cols = ['READINGDATE','MEASUREDLEVEL','TEMP','BP','MEASUREDDTW','DRIFTCORRECTION','WATERELEVATION','DTWBELOWGROUNDSURFACE']

for sheet in xl.sheet_names:
    #print(sheet)
    if str(sheet)[:2] == '10':
        if int(str(sheet)[:4]) < 1081:
            try:
                xldict[sheet] = xl.parse(sheet, parse_cols=("A,B,C,D,E,L,M,N"), skiprows=1,header=None)
                xldict[sheet].columns = cols
                xldict[sheet]['TAPE'] = 0
                xldict[sheet]['LOCATIONID'] = int(sheet)
                if xldict[sheet].loc[xldict[sheet].last_valid_index(),'DRIFTCORRECTION'] < 0.3:
                    add_data(xldict[sheet])
                else:
                    print('Well {:} drift too high'.format(xldict[sheet]['LOCATIONID'].values[-1]))
            except (RuntimeError,TypeError):
                print('format exception for well {:}'.format(sheet))
                pass


Well 1001 imported!
Well 1002 imported!
Well 1003 imported!
Well 1004 imported!
Well 1005 drift too high
Well 1006 imported!
Well 1007 imported!
Well 1008 imported!
Well 1009 imported!
Well 1010 imported!
Well 1011 imported!
Well 1012 imported!
Well 1013 imported!
Well 1014 imported!
Well 1015 imported!
Well 1016 imported!
Well 1018 imported!
Well 1019 imported!
Well 1020 imported!
Well 1021 imported!
Well 1022 imported!
Well 1023 imported!
Well 1024 imported!
Well 1025 imported!
Well 1026 imported!
Well 1028 imported!
Well 1029 imported!
Well 1030 imported!
Well 1031 imported!
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-2aef4b45af1d> in <module>()
     11                 xldict[sheet]['TAPE'] = 0
     12                 xldict[sheet]['LOCATIONID'] = int(sheet)
---> 13                 if xldict[sheet].loc[xldict[sheet].last_valid_index(),'DRIFTCORRECTION'] < 0.3:
     14                     add_data(xldict[sheet])
     15                 else:

TypeError: unorderable types: str() < float()

date piezo temp baro piezobaro elevation stickup cap measure manual id comp water elev dtw diff max min


In [ ]:
xl.parse('1003', parse_cols=("A,B,C,D,E,L,M,N"), skiprows=1,header=None)

In [12]:
import pandas as pd
df_input = pd.read_csv(r'C:\Users\PAULINKENBRANDT\PycharmProjects\Peeters_Piper\GW20130314-0057-s02.csv')

In [13]:
dat_piper = df_input[['Ca','Mg','Na','K','HCO3','CO3','Cl','SO4']].values