In [1]:
import pandas as pd
import numpy as np
import pickle
import os
root_directory = 'D:/github/w_vattenstatus/ekostat_calculator'#"../" #os.getcwd()
workspace_directory = root_directory + '/workspaces'
resource_directory = root_directory + '/resources'
#alias = 'lena'
user_id = 'test_user' #kanske ska vara off_line user?
workspace_alias = 'lena_indicator' # kustzonsmodellen_3daydata
# workspace_alias = 'kustzonsmodellen_3daydata'
# ## Initiate EventHandler
print(root_directory)
paths = {'user_id': user_id,
'workspace_directory': root_directory + '/workspaces',
'resource_directory': root_directory + '/resources',
'log_directory': 'D:/github' + '/log',
'test_data_directory': 'D:/github' + '/test_data',
'cache_directory': 'D:/github/w_vattenstatus/cache'}
In [3]:
sharkweb_matchfile = pd.read_csv(open(paths['resource_directory']+'/mappings/water_body_match_sharweb_SVAR_2012_2.txt'), sep = '\t')
In [4]:
current_matchfile = pd.read_csv(open(paths['resource_directory']+'/mappings/water_body_match.txt'), sep = '\t')
In [20]:
for type_code in sharkweb_matchfile.TYPE_AREA_CODE.unique():
type_code_new = current_matchfile.loc[current_matchfile.TYPE_AREA_CODE == type_code].TYPE_AREA_CODE.unique()
type_suffix_new = current_matchfile.loc[current_matchfile.TYPE_AREA_CODE == type_code].TYPE_AREA_SUFFIX.unique()
type_name_new = current_matchfile.loc[current_matchfile.TYPE_AREA_CODE == type_code].TYPE_AREA_NAME.unique()
print(type_code, type_code_new, type_suffix_new, type_name_new)
In [89]:
add_cols = [c for c in current_matchfile.columns if c not in sharkweb_matchfile.columns]
for ix in sharkweb_matchfile.index:
code = sharkweb_matchfile.loc[ix, 'VISS_EU_CD']
name = sharkweb_matchfile.loc[ix, 'WATER_BODY_NAME']
#print(current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'VISS_EU_CD'])
if not isinstance(current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'VISS_EU_CD'], pd.Series):
print(code)
elif current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'VISS_EU_CD'].empty:
print(code)
if not current_matchfile.loc[current_matchfile['NAMN'] == name, 'NAMN'].empty:
print(code, name)
for ac in add_cols:
sharkweb_matchfile.loc[ix, ac] = current_matchfile.loc[current_matchfile['NAMN'] == name, ac].values[0]
else:
#print(code)
#print(current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'VISS_EU_CD'].values[0])
for ac in add_cols:
sharkweb_matchfile.loc[ix, ac] = current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, ac].values[0]
#print(current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, ac])
#wb_name = current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'WATERBODY_NAME']
#type_name = current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'TYPE_AREA_NAME']
#MS_CD = current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, 'VISS_MS_CD']
In [63]:
current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code].empty
Out[63]:
In [55]:
code
Out[55]:
In [26]:
current_matchfile.loc[current_matchfile['VISS_EU_CD'] == code, ac].values[0]
Out[26]:
In [16]:
current_matchfile.columns
Out[16]:
In [83]:
sharkweb_matchfile.columns
Out[83]:
In [90]:
sharkweb_matchfile.to_csv(paths['resource_directory']+'/mappings/water_body_match_sharkweb_SVAR_2012_2_extended_new.txt', sep = '\t')
In [17]:
Out[17]:
In [2]:
', '.join(['a','b','c'])
Out[2]:
In [5]:
sharkweb_matchfile.head()
Out[5]:
In [41]:
new_df = pd.DataFrame()
new_df2 = new_df.append(pd.DataFrame(data = [[4,6]], index = [9], columns = ['A','B']))
new_df2 = new_df2.append(pd.DataFrame(data = [[8,10]], index = [5], columns = ['A','B']))
In [39]:
new_df2.head()
Out[39]:
In [42]:
new_df = pd.DataFrame()
new_df3 = new_df.append(pd.DataFrame(data = [[4,6]], index = [9], columns = ['C','D']))
new_df3 = new_df3.append(pd.DataFrame(data = [[8,10]], index = [5], columns = ['C','D']))
In [59]:
new_df2.merge(new_df3, left_index = True, right_index = True).ix[[9,5]]
Out[59]:
In [ ]:
In [53]:
sharkweb_matchfile.loc[sharkweb_matchfile.index[[4,8,3,21]]]
In [ ]:
In [ ]: