igdb/code/database/storage.py

31 lines
747 B
Python
Raw Normal View History

2020-01-06 08:31:21 +01:00
from db_setup import create_connection
from pandas import DataFrame, read_csv, to_sql
2020-01-06 11:12:55 +01:00
def create_dataframes() -> DataFrame:
files = {
"glacier": "../data/glacier.csv",
"annual__data": "../data/annual_data.csv",
"annual__change": "../data/annual_change.csv",
"users": "../data/users.csv",
}
df_list = {}
for csv in files.keys():
df_list[csv] = read_csv(files[csv], index=False)
return df_list
2020-01-06 08:31:21 +01:00
2020-01-06 11:12:55 +01:00
def insert_data(df_list, conn):
for key, value in df_list.items():
value.to_sql(key, con=conn, if_exists="replace", index=False)
2020-01-06 08:31:21 +01:00
def main():
conn = create_connection()
2020-01-06 11:12:55 +01:00
df_list = create_dataframes()
insert_data(df_list, conn)
2020-01-06 08:31:21 +01:00
if __name__ == "__main__":
main()