|
| 1 | +import DataUpdate |
| 2 | +import sqlite3 |
| 3 | +import pandas as pd |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +connection=sqlite3.connect("output/IFsHistSeries.db") |
| 7 | +cursor=connection.cursor() |
| 8 | + |
| 9 | +Aquastat=DataUpdate.AQUASTATData() |
| 10 | +Aquastat2=Aquastat.drop(["Country Name in IFs","Year"],axis=1) |
| 11 | + |
| 12 | + |
| 13 | +for col in (Aquastat2): |
| 14 | + data=Aquastat[["Country Name in IFs","Year",str(col)]] |
| 15 | + data1=pd.pivot_table(data,values=[str(col)],index=["Country Name in IFs"], columns=["Year"],aggfunc=[np.sum]) |
| 16 | + |
| 17 | + #Get Most Recent Year |
| 18 | + dataRecent=data.dropna() |
| 19 | + dataRecent=dataRecent.sort_values(["Country Name in IFs","Year"]) |
| 20 | + dataRecent=dataRecent.drop_duplicates("Country Name in IFs",keep='last') |
| 21 | + dataRecent.reset_index() |
| 22 | + dataRecent.columns=["Country Name in IFs","MostRecentYear","MostRecentValue"] |
| 23 | + |
| 24 | + #Get Earliest Year |
| 25 | + dataEarliest = data.dropna() |
| 26 | + dataEarliest= dataEarliest.sort_values(["Country Name in IFs", "Year"]) |
| 27 | + dataEarliest = dataEarliest.drop_duplicates("Country Name in IFs", keep='first') |
| 28 | + dataEarliest.reset_index() |
| 29 | + dataEarliest.columns = ["Country Name in IFs", "EarliestYear", "EarliestValue"] |
| 30 | + |
| 31 | + data1 = pd.DataFrame(data1.to_records()) |
| 32 | + val="('sum', '"+str(col)+"', " |
| 33 | + data1.columns = [hdr.replace(val,"").replace(")", "").replace("'", "") \ |
| 34 | + for hdr in data1.columns] |
| 35 | + |
| 36 | + data1=pd.merge(data1,dataRecent,how='left',left_on="Country Name in IFs",right_on="Country Name in IFs") |
| 37 | + data1=pd.merge(data1,dataEarliest,how='left',left_on="Country Name in IFs",right_on="Country Name in IFs") |
| 38 | + print(data1.head()) |
| 39 | + |
| 40 | + data1.to_sql(name=str("Series").strip()+str(col).strip(), con=connection, if_exists="replace", index=False) |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +IMFExp=DataUpdate.IMFGFSExpenditureData() |
| 46 | +IMFExp.to_sql(name="IMFExpenditure", con=connection, if_exists="replace", index=False) |
| 47 | + |
| 48 | + |
| 49 | +FAO=DataUpdate.FAOFBS() |
| 50 | +FAO.to_sql(name="FAOFoodBalanceSheetAggregated", con=connection, if_exists="replace", index=False) |
| 51 | + |
| 52 | +WDI=DataUpdate.WDIData() |
| 53 | +WDI.to_sql(name="WorldDevelopmentIndicators",con=connection,if_exists="replace",index=False) |
| 54 | + |
| 55 | +UIS=DataUpdate.UISData() |
| 56 | +UIS.to_sql(name="UISEducationData",con=connection,if_exists="replace",index=False) |
| 57 | + |
| 58 | + |
| 59 | +IMF=DataUpdate.IMFGFSRevenueData() |
| 60 | +IMF.to_sql(name="IMFRevenue", con=connection, if_exists="replace", index=False) |
| 61 | + |
| 62 | +HealthDet=DataUpdate.IHMEDetailedDeathsData() |
| 63 | +HealthDet.to_sql(name="HealthDataDetailed",con=connection,if_exists="replace",index=False) |
| 64 | + |
| 65 | +Health=DataUpdate.IHMEHistoricalDeathData(sex_name="Both") |
| 66 | +Health.to_sql(name="HealthData",con=connection,if_exists="replace",index=False) |
| 67 | + |
| 68 | +Fish=DataUpdate.FAOFBSFish() |
| 69 | +Fish.to_sql(name="FAOFishData", con=connection, if_exists="replace", index=False) |
| 70 | + |
| 71 | + |
| 72 | + |
0 commit comments