Add csv parser

This commit is contained in:
coolneng 2020-01-06 06:34:35 +01:00
parent 8f31f6ff84
commit cbc1c08350
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
4 changed files with 19 additions and 8 deletions

View File

@ -30,8 +30,8 @@ db = create_connection()
class Glacier(db.Model):
uid = db.Column(db.Integer, primary_key=True)
country = db.Column(db.String(30))
name = db.Column(db.String(30))
country = db.Column(db.String(60))
name = db.Column(db.String(60))
def __init__(self, uid, country, name):
self.uid = uid
@ -73,7 +73,7 @@ class Annual_Change(db.Model):
self.year = year
class Users(db.Model):
class User(db.Model):
uid = db.Column(db.Integer, primary_key=True)
registration_date = db.Column(db.DateTime, nullable=False)

View File

@ -1,5 +1,6 @@
from pandas import read_csv, concat, DataFrame
from iso3166 import countries as co
from pandas import DataFrame, concat, read_csv
from csv import QUOTE_NONNUMERIC
def country_conversion(political_unit) -> str:
@ -15,16 +16,26 @@ def select_columns() -> DataFrame:
"YEAR",
"AREA_SURVEY_YEAR",
"AREA_CHANGE",
"THICKNESS CHANGE",
"THICKNESS_CHG",
"VOLUME_CHANGE",
]
iter_csv = read_csv(
"../../data/WGMS-FoG-2019-12-D-CHANGE.csv",
"../data/WGMS-FoG-2019-12-D-CHANGE.csv",
skipinitialspace=True,
usecols=fields,
iterator=True,
chunksize=100,
converters={"YEAR": country_conversion},
converters={"POLITICAL_UNIT": country_conversion},
)
data = concat([chunk[chunk["YEAR"] > min_year] for chunk in iter_csv])
return data
def main():
df = select_columns()
database = "../data/igdb.csv"
df.to_csv(database, index=False, quoting=QUOTE_NONNUMERIC)
if __name__ == "__main__":
main()

0
code/database/storage.py Normal file
View File

View File

@ -18,7 +18,7 @@ datos relevantes para estudios acerca del cambio climático, y acotando éstos a
*** Datos
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/
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/