Skip to content
Snippets Groups Projects
Commit f97e69ce authored by Clemens Berteld's avatar Clemens Berteld
Browse files

Matrix gets laoded into database and filled with data.

Weightet interpolation or matrix filling needs to be reviewed. Same values for almost every point in the matrix.
parent 168d8d23
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ def loadDWDGauges():
global stationList
print("load DWD Gauges")
# load station list from dwd
stationList = pd.read_csv(stationURL, delimiter=";", skiprows=0, usecols=[0,2,3,5], names=["id","lon","lat","country"], header=0, encoding="ISO-8859-1 ")
stationList = pd.read_csv(stationURL, delimiter=";", skiprows=0, usecols=[0,2,3,5], names=["id","lat","lon","country"], header=0, encoding="ISO-8859-1 ")
stationList = stationList.dropna(how="any", axis=0)
stationList['country'] = stationList['country'].str.strip()
stationList['lon'] = stationList['lon'].str.strip()
......
......@@ -7,19 +7,19 @@ export the stationlist to database
@author: geopeter
"""
import time
import psycopg2
import psycopg2.extras
from psycopg2 import sql
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
import configparser
from dataacquisition.GetAverageData import get_interpolation_data_for_point
cfg = configparser.ConfigParser()
cfg.read('config.ini')
assert "POSTGRES" in cfg, "missing POSTGRES in config.ini"
param_postgres = cfg["POSTGRES"]
stationGPD = None
......@@ -31,6 +31,7 @@ def create_db(db_name):
with connection.cursor() as cursor:
create_db_query = sql.SQL("""CREATE DATABASE {};""".format(db_name))
cursor.execute(create_db_query)
cursor.close()
connection.close()
......@@ -38,11 +39,9 @@ def drop_db(db_name):
if dbexists(db_name):
print("Drop DB: ", db_name)
try:
connection = psycopg2.connect(dbname='postgres', user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"])
connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # Needs to be in AUTOCOMMIT mode for creating database
with connection.cursor() as cursor:
cursor.execute("DROP DATABASE {};".format(db_name))
connection.close()
with psycopg2.connect(database=db_name, user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"]) as connection:
with connection.cursor() as cursor:
cursor.execute("DROP DATABASE {};".format(db_name))
except psycopg2.DatabaseError as error:
# do nothing, because test db is clean
print(error.message)
......@@ -51,13 +50,12 @@ def drop_db(db_name):
def dbexists(db_name):
try:
connection = psycopg2.connect(dbname='postgres', user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"])
cursor = connection.cursor()
cursor.execute("SELECT datname FROM pg_database WHERE datname LIKE '{}';".format(db_name))
with psycopg2.connect(database=db_name, user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"]) as connection:
with connection.cursor() as cursor:
cursor.execute("SELECT datname FROM pg_database WHERE datname LIKE '{}';".format(db_name))
db_exists = cursor.fetchall()[0]
connection.close()
return True
db_exists = cursor.fetchall()[0]
return True
except(Exception, psycopg2.DatabaseError) as error:
# do nothing, because test db is clean
return False
......@@ -87,6 +85,51 @@ def create_table(station_list, db_name):
query = sql.SQL("""CREATE TABLE stations ({});""".format(columns_clean))
#print(query)
cursor.execute(query)
cursor.execute('CREATE EXTENSION postgis;')
def insert_empty_matrix_into_db():
with psycopg2.connect(database=param_postgres['dbName'], user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"]) as connection:
with connection.cursor() as cursor:
with open('clipped_matrix_10x10.csv', 'r') as matrix:
matrix_data = matrix.readlines()
for line in matrix_data[1:]:
values = '' # Used in second parameter of cursor.execute() (Avoids SQL injection)
data = line.split(';')
id = int("9999" + data[0].replace('"', ''))
lon = float(data[1])
lat = float(data[2].replace('\n', ''))
for n in [id, lon, lat]:
values = (*values, n) # adding n to existing tuple
query = sql.SQL("INSERT INTO STATIONS (id, lon, lat, country) "
"VALUES ({id}, {lon}, {lat}, 'Germany');").format(id=sql.Placeholder(), lon=sql.Placeholder(), lat=sql.Placeholder())
# print(query.as_string(cursor))
# print(values)
cursor.execute(query, values)
print('Inserted empty matrix into database')
def create_matrix_data():
with psycopg2.connect(database=param_postgres['dbName'], user=param_postgres["user"], password=param_postgres["password"], host=param_postgres["host"], port=param_postgres["port"],
keepalives=1, keepalives_idle=30, keepalives_interval=10, keepalives_count=5) as connection:
with connection.cursor() as cursor:
cursor.execute("SELECT id, lon, lat FROM stations WHERE file is NULL;")
matrix_points = cursor.fetchall()
update_data = []
for point in matrix_points:
id = point[0]
lon = point[1]
lat = point[2]
print(lat, lon)
interpolation_data = get_interpolation_data_for_point(lat, lon, sql.SQL('*'))
for year, value in interpolation_data.items():
update_data.append({'year': year, 'value': value, 'id': id})
print(update_data)
query = sql.SQL("""UPDATE stations SET "%(year)s" = %(value)s WHERE id = %(id)s; """)
psycopg2.extras.execute_batch(cursor, query, update_data) # 2 times faster than using execute() in a for loop, ~20 mins instead of 40
def insert_data(station_list, db_name):
......@@ -101,9 +144,9 @@ def insert_data(station_list, db_name):
# create (col1,col2,...)
# As integers like 2018, 2017, etc. are not possible as column names, double quotes have to be added. This requires some tricks and cleanups
columns = []
for column in df_columns:
columns.append('"' + column + '"')
columns = ['"' + column + '"' for column in df_columns]
# for column in df_columns:
# columns.append('"' + column + '"')
columns = str(columns).replace('[', '').replace(']', '').replace("'", "").replace('\n', '').replace(' ', '')
station_list = station_list.round(decimals=3)
......@@ -118,3 +161,9 @@ def insert_data(station_list, db_name):
def export(station_list):
check_for_db_existence(station_list, param_postgres['dbName'])
insert_data(station_list, param_postgres['dbName'])
insert_empty_matrix_into_db()
start_time = time.time()
create_matrix_data()
print((time.time() - start_time), 'seconds')
......@@ -33,6 +33,7 @@ def get_neighbours(cursor, lat, lon, columns):
SELECT array_to_json(array_agg(row_to_json(t))) from (
SELECT {columns}, ST_Distance(ST_MakePoint(lon, lat), ST_MakePoint({lon}, {lat})) AS distance
FROM stations
WHERE file IS NOT NULL
ORDER BY distance
LIMIT {amount_neighbours}
) t;
......@@ -59,17 +60,19 @@ def calc_idw(neighbours, years):
weighted_values = {}
for year in years:
values = []
# print(neighbours)
distances = []
for neighbour in neighbours:
distances.append(neighbour['distance'])
for neighbour in neighbours:
normalizer = float(param_interpol["amount_neighbours"]) / sum(distances)
weight = neighbour['distance'] * normalizer
print('weight', weight)
if not neighbour[str(year)] == 'NaN': values.append(neighbour[str(year)] * weight)
avg = round(sum(values) / len(values), 3)
weighted_values[year] = avg
try:
avg = round(sum(values) / len(values), 3)
weighted_values[year] = avg
except ZeroDivisionError:
# print('No Data (NaN in DB)')
pass
return weighted_values
......
This diff is collapsed.
{
"type": "FeatureCollection",
"name": "clipped_matrix_10x10_25833",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::25833" } },
"features": [
]
}
This diff is collapsed.
id;lon;lat
"51";6.07;51.84
"52";6.12;51.62
"54";6.20;51.18
"55";6.25;50.96
"56";6.29;50.73
"57";6.33;50.51
"58";6.37;50.29
"59";6.41;50.07
"60";6.45;49.84
"61";6.49;49.62
"87";6.43;51.87
"88";6.47;51.65
"89";6.52;51.43
"90";6.56;51.20
"91";6.60;50.98
"92";6.64;50.76
"93";6.68;50.54
"94";6.72;50.31
"95";6.76;50.09
"96";6.79;49.87
"97";6.83;49.65
"98";6.87;49.42
"114";6.40;53.90
"115";6.45;53.68
"123";6.79;51.90
"124";6.83;51.67
"125";6.87;51.45
"126";6.91;51.23
"127";6.95;51.01
"128";6.99;50.78
"129";7.03;50.56
"130";7.07;50.34
"131";7.10;50.12
"132";7.14;49.89
"133";7.17;49.67
"134";7.21;49.45
"135";7.25;49.23
"149";6.73;54.15
"150";6.78;53.92
"151";6.82;53.70
"152";6.87;53.48
"156";7.03;52.59
"158";7.11;52.14
"159";7.15;51.92
"160";7.19;51.70
"161";7.23;51.48
"162";7.27;51.25
"163";7.30;51.03
"164";7.34;50.81
"165";7.38;50.59
"166";7.41;50.36
"167";7.45;50.14
"168";7.48;49.92
"169";7.52;49.69
"170";7.55;49.47
"171";7.59;49.25
"176";7.75;48.13
"177";7.78;47.91
"178";7.81;47.69
"185";7.11;54.17
"186";7.16;53.95
"187";7.20;53.73
"188";7.24;53.50
"189";7.28;53.28
"190";7.32;53.06
"191";7.36;52.84
"192";7.40;52.61
"193";7.44;52.39
"194";7.47;52.17
"195";7.51;51.95
"196";7.55;51.72
"197";7.59;51.50
"198";7.62;51.28
"199";7.66;51.05
"200";7.69;50.83
"201";7.73;50.61
"202";7.76;50.38
"203";7.80;50.16
"204";7.83;49.94
"205";7.86;49.72
"206";7.89;49.49
"207";7.93;49.27
"208";7.96;49.05
"210";8.02;48.60
"211";8.05;48.38
"212";8.08;48.15
"213";8.11;47.93
"214";8.14;47.71
"222";7.53;53.97
"223";7.57;53.75
"224";7.61;53.53
"225";7.65;53.31
"226";7.69;53.08
"227";7.73;52.86
"228";7.76;52.64
"229";7.80;52.41
"230";7.84;52.19
"231";7.87;51.97
"232";7.91;51.74
"233";7.94;51.52
"234";7.98;51.30
"235";8.01;51.08
"236";8.05;50.85
"237";8.08;50.63
"238";8.11;50.41
"239";8.14;50.18
"240";8.18;49.96
"241";8.21;49.74
"242";8.24;49.51
"243";8.27;49.29
"244";8.30;49.07
"245";8.33;48.84
"246";8.36;48.62
"247";8.39;48.40
"248";8.42;48.17
"249";8.45;47.95
"257";7.87;54.22
"258";7.91;54.00
"259";7.95;53.77
"260";7.99;53.55
"261";8.02;53.33
"262";8.06;53.10
"263";8.10;52.88
"264";8.13;52.66
"265";8.17;52.44
"266";8.20;52.21
"267";8.23;51.99
"268";8.27;51.77
"269";8.30;51.54
"270";8.33;51.32
"271";8.37;51.10
"272";8.40;50.87
"273";8.43;50.65
"274";8.46;50.43
"275";8.49;50.20
"276";8.52;49.98
"277";8.55;49.76
"278";8.58;49.53
"279";8.61;49.31
"280";8.64;49.09
"281";8.67;48.86
"282";8.70;48.64
"283";8.72;48.41
"284";8.75;48.19
"285";8.78;47.97
"286";8.80;47.74
"290";8.14;54.91
"291";8.18;54.69
"292";8.22;54.47
"293";8.25;54.24
"294";8.29;54.02
"295";8.33;53.80
"296";8.36;53.57
"297";8.40;53.35
"298";8.43;53.13
"299";8.46;52.90
"300";8.50;52.68
"301";8.53;52.46
"302";8.56;52.23
"303";8.60;52.01
"304";8.63;51.79
"305";8.66;51.56
"306";8.69;51.34
"307";8.72;51.12
"308";8.75;50.89
"309";8.78;50.67
"310";8.81;50.45
"311";8.84;50.22
"312";8.87;50.00
"313";8.90;49.77
"314";8.92;49.55
"315";8.95;49.33
"316";8.98;49.10
"317";9.01;48.88
"318";9.03;48.66
"319";9.06;48.43
"320";9.09;48.21
"321";9.11;47.99
"326";8.53;54.93
"327";8.56;54.71
"328";8.60;54.49
"329";8.63;54.26
"330";8.67;54.04
"331";8.70;53.82
"332";8.74;53.59
"333";8.77;53.37
"334";8.80;53.15
"335";8.83;52.92
"336";8.87;52.70
"337";8.90;52.48
"338";8.93;52.25
"339";8.96;52.03
"340";8.99;51.81
"341";9.02;51.58
"342";9.05;51.36
"343";9.08;51.13
"344";9.10;50.91
"345";9.13;50.69
"346";9.16;50.46
"347";9.19;50.24
"348";9.22;50.02
"349";9.24;49.79
"350";9.27;49.57
"351";9.29;49.34
"352";9.32;49.12
"353";9.35;48.90
"354";9.37;48.67
"355";9.40;48.45
"356";9.42;48.23
"357";9.44;48.00
"358";9.47;47.78
"362";8.92;54.95
"363";8.95;54.73
"364";8.98;54.51
"365";9.02;54.28
"366";9.05;54.06
"367";9.08;53.84
"368";9.11;53.61
"369";9.14;53.39
"370";9.17;53.16
"371";9.20;52.94
"372";9.23;52.72
"373";9.26;52.49
"374";9.29;52.27
"375";9.32;52.05
"376";9.35;51.82
"377";9.38;51.60
"378";9.40;51.38
"379";9.43;51.15
"380";9.46;50.93
"381";9.48;50.70
"382";9.51;50.48
"383";9.54;50.26
"384";9.56;50.03
"385";9.59;49.81
"386";9.61;49.59
"387";9.64;49.36
"388";9.66;49.14
"389";9.69;48.91
"390";9.71;48.69
"391";9.73;48.47
"392";9.76;48.24
"393";9.78;48.02
"394";9.80;47.79
"395";9.82;47.57
"398";9.31;54.97
"399";9.34;54.75
"400";9.37;54.52
"401";9.40;54.30
"402";9.43;54.08
"403";9.46;53.85
"404";9.49;53.63
"405";9.52;53.41
"406";9.55;53.18
"407";9.57;52.96
"408";9.60;52.74
"409";9.63;52.51
"410";9.66;52.29
"411";9.68;52.06
"412";9.71;51.84
"413";9.74;51.62
"414";9.76;51.39
"415";9.79;51.17
"416";9.81;50.94
"417";9.84;50.72
"418";9.86;50.50
"419";9.89;50.27
"420";9.91;50.05
"421";9.93;49.82
"422";9.96;49.60
"423";9.98;49.38
"424";10.00;49.15
"425";10.03;48.93
"426";10.05;48.70
"427";10.07;48.48
"428";10.09;48.26
"429";10.11;48.03
"430";10.13;47.81
"431";10.15;47.58
"435";9.72;54.77
"436";9.75;54.54
"437";9.78;54.32
"438";9.81;54.09
"439";9.84;53.87
"440";9.86;53.65
"441";9.89;53.42
"442";9.92;53.20
"443";9.94;52.98
"444";9.97;52.75
"445";10.00;52.53
"446";10.02;52.30
"447";10.05;52.08
"448";10.07;51.86
"449";10.10;51.63
"450";10.12;51.41
"451";10.14;51.18
"452";10.17;50.96
"453";10.19;50.74
"454";10.21;50.51
"455";10.24;50.29
"456";10.26;50.06
"457";10.28;49.84
"458";10.30;49.62
"459";10.32;49.39
"460";10.34;49.17
"461";10.37;48.94
"462";10.39;48.72
"463";10.41;48.49
"464";10.43;48.27
"465";10.45;48.05
"466";10.47;47.82
"467";10.49;47.60
"472";10.14;54.56
"473";10.16;54.33
"474";10.19;54.11
"475";10.22;53.89
"476";10.24;53.66
"477";10.27;53.44
"478";10.29;53.21
"479";10.32;52.99
"480";10.34;52.77
"481";10.36;52.54
"482";10.39;52.32
"483";10.41;52.09
"484";10.43;51.87
"485";10.46;51.65
"486";10.48;51.42
"487";10.50;51.20
"488";10.52;50.97
"489";10.54;50.75
"490";10.56;50.53
"491";10.59;50.30
"492";10.61;50.08
"493";10.63;49.85
"494";10.65;49.63
"495";10.67;49.40
"496";10.69;49.18
"497";10.71;48.96
"498";10.72;48.73
"499";10.74;48.51
"500";10.76;48.28
"501";10.78;48.06
"502";10.80;47.83
"503";10.82;47.61
"509";10.55;54.35
"510";10.57;54.12
"511";10.60;53.90
"512";10.62;53.68
"513";10.64;53.45
"514";10.66;53.23
"515";10.69;53.00
"516";10.71;52.78
"517";10.73;52.56
"518";10.75;52.33
"519";10.77;52.11
"520";10.80;51.88
"521";10.82;51.66
"522";10.84;51.44
"523";10.86;51.21
"524";10.88;50.99
"525";10.90;50.76
"526";10.92;50.54
"527";10.94;50.31
"528";10.95;50.09
"529";10.97;49.87
"530";10.99;49.64
"531";11.01;49.42
"532";11.03;49.19
"533";11.05;48.97
"534";11.06;48.74
"535";11.08;48.52
"536";11.10;48.30
"537";11.12;48.07
"538";11.13;47.85
"539";11.15;47.62
"544";10.91;54.59
"545";10.93;54.36
"546";10.95;54.14
"547";10.97;53.91
"548";11.00;53.69
"549";11.02;53.47
"550";11.04;53.24
"551";11.06;53.02
"552";11.08;52.79
"553";11.10;52.57
"554";11.12;52.34
"555";11.14;52.12
"556";11.16;51.90
"557";11.18;51.67
"558";11.20;51.45
"559";11.21;51.22
"560";11.23;51.00
"561";11.25;50.77
"562";11.27;50.55
"563";11.29;50.33
"564";11.30;50.10
"565";11.32;49.88
"566";11.34;49.65
"567";11.35;49.43
"568";11.37;49.20
"569";11.39;48.98
"570";11.40;48.76
"571";11.42;48.53
"572";11.44;48.31
"573";11.45;48.08
"574";11.47;47.86
"575";11.48;47.63
"581";11.31;54.37
"582";11.33;54.15
"583";11.35;53.93
"584";11.37;53.70
"585";11.39;53.48
"586";11.41;53.25
"587";11.43;53.03
"588";11.45;52.80
"589";11.47;52.58
"590";11.49;52.36
"591";11.50;52.13
"592";11.52;51.91
"593";11.54;51.68
"594";11.55;51.46
"595";11.57;51.23
"596";11.59;51.01
"597";11.60;50.79
"598";11.62;50.56
"599";11.64;50.34
"600";11.65;50.11
"601";11.67;49.89
"602";11.68;49.66
"603";11.70;49.44
"604";11.71;49.21
"605";11.73;48.99
"606";11.74;48.77
"607";11.76;48.54
"608";11.77;48.32
"609";11.79;48.09
"610";11.80;47.87
"611";11.81;47.64
"617";11.70;54.39
"618";11.72;54.16
"619";11.73;53.94
"620";11.75;53.71
"621";11.77;53.49
"622";11.79;53.26
"623";11.80;53.04
"624";11.82;52.82
"625";11.84;52.59
"626";11.85;52.37
"627";11.87;52.14
"628";11.88;51.92
"629";11.90;51.69
"630";11.91;51.47
"631";11.93;51.24
"632";11.94;51.02
"633";11.96;50.80
"634";11.97;50.57
"635";11.99;50.35
"636";12.00;50.12
"637";12.02;49.90
"638";12.03;49.67
"639";12.04;49.45
"640";12.06;49.22
"641";12.07;49.00
"642";12.08;48.77
"643";12.10;48.55
"644";12.11;48.33
"645";12.12;48.10
"646";12.13;47.88
"647";12.15;47.65
"653";12.08;54.40
"654";12.10;54.17
"655";12.11;53.95
"656";12.13;53.72
"657";12.15;53.50
"658";12.16;53.27
"659";12.18;53.05
"660";12.19;52.82
"661";12.20;52.60
"662";12.22;52.38
"663";12.23;52.15
"664";12.25;51.93
"665";12.26;51.70
"666";12.27;51.48
"667";12.29;51.25
"668";12.30;51.03
"669";12.31;50.80
"670";12.33;50.58
"671";12.34;50.35
"673";12.36;49.91
"674";12.38;49.68
"675";12.39;49.46
"676";12.40;49.23
"677";12.41;49.01
"678";12.42;48.78
"679";12.43;48.56
"680";12.45;48.33
"681";12.46;48.11
"682";12.47;47.88
"683";12.48;47.66
"689";12.47;54.40
"690";12.48;54.18
"691";12.50;53.96
"692";12.51;53.73
"693";12.52;53.51
"694";12.54;53.28
"695";12.55;53.06
"696";12.56;52.83
"697";12.57;52.61
"698";12.59;52.38
"699";12.60;52.16
"700";12.61;51.93
"701";12.62;51.71
"702";12.63;51.49
"703";12.64;51.26
"704";12.66;51.04
"705";12.67;50.81
"706";12.68;50.59
"712";12.74;49.24
"713";12.75;49.01
"714";12.76;48.79
"715";12.77;48.56
"716";12.78;48.34
"718";12.80;47.89
"719";12.81;47.67
"725";12.85;54.41
"726";12.86;54.19
"727";12.88;53.96
"728";12.89;53.74
"729";12.90;53.51
"730";12.91;53.29
"731";12.92;53.06
"732";12.93;52.84
"733";12.94;52.62
"734";12.95;52.39
"735";12.96;52.17
"736";12.97;51.94
"737";12.98;51.72
"738";12.99;51.49
"739";13.00;51.27
"740";13.01;51.04
"741";13.02;50.82
"742";13.03;50.59
"748";13.09;49.25
"749";13.09;49.02
"750";13.10;48.80
"751";13.11;48.57
"752";13.12;48.35
"760";13.23;54.64
"761";13.24;54.42
"762";13.25;54.19
"763";13.26;53.97
"764";13.27;53.74
"765";13.28;53.52
"766";13.28;53.30
"767";13.29;53.07
"768";13.30;52.85
"769";13.31;52.62
"770";13.32;52.40
"771";13.33;52.17
"772";13.34;51.95
"773";13.34;51.72
"774";13.35;51.50
"775";13.36;51.27
"776";13.37;51.05
"777";13.38;50.82
"786";13.44;48.80
"787";13.45;48.58
"796";13.62;54.65
"797";13.62;54.42
"798";13.63;54.20
"799";13.64;53.97
"800";13.65;53.75
"801";13.65;53.52
"802";13.66;53.30
"803";13.67;53.08
"804";13.67;52.85
"805";13.68;52.63
"806";13.69;52.40
"807";13.69;52.18
"808";13.70;51.95
"809";13.71;51.73
"810";13.71;51.50
"811";13.72;51.28
"812";13.73;51.05
"813";13.73;50.83
"822";13.78;48.80
"823";13.79;48.58
"834";14.01;54.20
"835";14.02;53.98
"836";14.02;53.75
"837";14.03;53.53
"838";14.03;53.30
"839";14.04;53.08
"840";14.04;52.85
"841";14.05;52.63
"842";14.05;52.40
"843";14.06;52.18
"844";14.06;51.96
"845";14.07;51.73
"846";14.07;51.51
"847";14.08;51.28
"848";14.08;51.06
"849";14.09;50.83
"874";14.41;53.31
"877";14.42;52.63
"878";14.42;52.41
"879";14.42;52.18
"880";14.43;51.96
"881";14.43;51.73
"882";14.43;51.51
"883";14.44;51.28
"884";14.44;51.06
"918";14.79;51.51
"919";14.79;51.28
"920";14.80;51.06
"921";14.80;50.83
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -9,8 +9,19 @@
# print(query.as_string(cursor))
weights = [2, 1.25, 0.75, 0.6, 0.4]
neighbours = [{'2015': 'NaN', '2010': 9.333, '2014': 'NaN', '1998': 'NaN', 'distance': 0.0223606797750006}, {'2015': 11.233, '2010': 8.883, '2014': 11.458, '1998': 10.05, 'distance': 0.0300000000000011}, {'2015': 11.133, '2010': 8.767, '2014': 11.467, '1998': 'NaN', 'distance': 0.108166538263921}, {'2015': 10.667, '2010': 8.208, '2014': 11.025, '1998': 9.8, 'distance': 0.111803398874988}, {'2015': 10.667, '2010': 8.35, '2014': 10.908, '1998': 'NaN', 'distance': 0.176918060129539}]
# weights = [2, 1.25, 0.75, 0.6, 0.4]
# neighbours = [{'2015': 'NaN', '2010': 9.333, '2014': 'NaN', '1998': 'NaN', 'distance': 0.0223606797750006}, {'2015': 11.233, '2010': 8.883, '2014': 11.458, '1998': 10.05, 'distance': 0.0300000000000011}, {'2015': 11.133, '2010': 8.767, '2014': 11.467, '1998': 'NaN', 'distance': 0.108166538263921}, {'2015': 10.667, '2010': 8.208, '2014': 11.025, '1998': 9.8, 'distance': 0.111803398874988}, {'2015': 10.667, '2010': 8.35, '2014': 10.908, '1998': 'NaN', 'distance': 0.176918060129539}]
#
# for weight, neighbour in zip(weights, neighbours):
# print(weight, neighbour['2015'])
# list_a = [1,2,3,4,5,6]
# list_b = [x * 2 for x in list_a if x % 2 == 0]
# print(list_b)
for weight, neighbour in zip(weights, neighbours):
print(weight, neighbour['2015'])
list_a = [1,2,3,4,5,6,7,8,9,10]
new_list = list_a[0::2]
print(new_list)
\ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment