Add csv parser
This commit is contained in:
parent
8f31f6ff84
commit
cbc1c08350
|
@ -30,8 +30,8 @@ db = create_connection()
|
||||||
|
|
||||||
class Glacier(db.Model):
|
class Glacier(db.Model):
|
||||||
uid = db.Column(db.Integer, primary_key=True)
|
uid = db.Column(db.Integer, primary_key=True)
|
||||||
country = db.Column(db.String(30))
|
country = db.Column(db.String(60))
|
||||||
name = db.Column(db.String(30))
|
name = db.Column(db.String(60))
|
||||||
|
|
||||||
def __init__(self, uid, country, name):
|
def __init__(self, uid, country, name):
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
|
@ -73,7 +73,7 @@ class Annual_Change(db.Model):
|
||||||
self.year = year
|
self.year = year
|
||||||
|
|
||||||
|
|
||||||
class Users(db.Model):
|
class User(db.Model):
|
||||||
uid = db.Column(db.Integer, primary_key=True)
|
uid = db.Column(db.Integer, primary_key=True)
|
||||||
registration_date = db.Column(db.DateTime, nullable=False)
|
registration_date = db.Column(db.DateTime, nullable=False)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from pandas import read_csv, concat, DataFrame
|
|
||||||
from iso3166 import countries as co
|
from iso3166 import countries as co
|
||||||
|
from pandas import DataFrame, concat, read_csv
|
||||||
|
from csv import QUOTE_NONNUMERIC
|
||||||
|
|
||||||
|
|
||||||
def country_conversion(political_unit) -> str:
|
def country_conversion(political_unit) -> str:
|
||||||
|
@ -15,16 +16,26 @@ def select_columns() -> DataFrame:
|
||||||
"YEAR",
|
"YEAR",
|
||||||
"AREA_SURVEY_YEAR",
|
"AREA_SURVEY_YEAR",
|
||||||
"AREA_CHANGE",
|
"AREA_CHANGE",
|
||||||
"THICKNESS CHANGE",
|
"THICKNESS_CHG",
|
||||||
"VOLUME_CHANGE",
|
"VOLUME_CHANGE",
|
||||||
]
|
]
|
||||||
iter_csv = read_csv(
|
iter_csv = read_csv(
|
||||||
"../../data/WGMS-FoG-2019-12-D-CHANGE.csv",
|
"../data/WGMS-FoG-2019-12-D-CHANGE.csv",
|
||||||
skipinitialspace=True,
|
skipinitialspace=True,
|
||||||
usecols=fields,
|
usecols=fields,
|
||||||
iterator=True,
|
iterator=True,
|
||||||
chunksize=100,
|
chunksize=100,
|
||||||
converters={"YEAR": country_conversion},
|
converters={"POLITICAL_UNIT": country_conversion},
|
||||||
)
|
)
|
||||||
data = concat([chunk[chunk["YEAR"] > min_year] for chunk in iter_csv])
|
data = concat([chunk[chunk["YEAR"] > min_year] for chunk in iter_csv])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
df = select_columns()
|
||||||
|
database = "../data/igdb.csv"
|
||||||
|
df.to_csv(database, index=False, quoting=QUOTE_NONNUMERIC)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -18,7 +18,7 @@ datos relevantes para estudios acerca del cambio climático, y acotando éstos a
|
||||||
*** Datos
|
*** Datos
|
||||||
|
|
||||||
1. *RD1*: Datos del glaciar
|
1. *RD1*: Datos del glaciar
|
||||||
- País - /Cadena de 30 caracteres máximo/
|
- País - /Cadena de 60 caracteres máximo/
|
||||||
- Nombre del glaciar - /Cadena de 60 caracteres máximo/
|
- Nombre del glaciar - /Cadena de 60 caracteres máximo/
|
||||||
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/
|
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue