In [1]:
import pandas as pd
from sqlalchemy import create_engine

In [40]:
BT_all = pd.read_csv('/users/jdlara/Documents/Box Sync/EPIC-Biomass/Biomass data/BillionTonUpdateForestResources/KDF_Frst_LOGT.dat', encoding='UTF-8', delimiter = ',', dtype = {'fcode':str})
BT_all = BT_all.fillna(0)
FIPS_all = pd.read_csv('/users/jdlara/Documents/Box Sync/EPIC-Biomass/Biomass data/BillionTonUpdateForestResources/fips_codes2.csv', encoding='UTF-8', dtype = {'State FIPS Code':str,'County FIPS Code':str})
FIPS_all['fcode'] = FIPS_all[['State FIPS Code', 'County FIPS Code']].apply(lambda x: ''.join(x), axis=1)
FIPS_all = FIPS_all.loc[FIPS_all['Entity Description'] == 'County']
FIPS_all = FIPS_all.set_index('fcode')

In [41]:
df_join = BT_all.join(FIPS_all, on = 'fcode')

In [4]:
engine = create_engine('postgresql+pg8000://jdlara:Amadeus-2010@switch-db2.erg.berkeley.edu:5432/apl_cec?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory', isolation_level="AUTOCOMMIT")

In [46]:
df_join.to_sql('KDF_Frst_LOGT', engine, schema='Billion_TON', if_exists = 'replace')

In [5]:
engine_source = create_engine('postgresql+pg8000://jdlara:Bario-140@switch-db2.erg.berkeley.edu:5432/switch_gis?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory')
engine_dest = create_engine('postgresql+pg8000://jdlara:Bario-140@switch-db2.erg.berkeley.edu:5432/APL_CEC?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory')
df_r = pd.read_sql_query('select * from ventyx_may_2012.maj_road_polyline',engine_source)
df_subs = pd.read_sql_query('select * from ventyx_may_2012.e_buses_wecc_point',engine_source)
df_subs = df_subs.set_index('gid')
df_counties = df_counties.set_index('gid')
df_counties.to_sql('Counties', engine, schema='General_GIS_DATA', if_exists = 'replace')
#df_subs.to_sql('WECC_Substations', engine, schema='General_GIS_DATA', if_exists = 'replace')

In [3]:
engine_source = create_engine('postgresql+pg8000://jdlara:Amadeus-2010@switch-db2.erg.berkeley.edu:5432/switch_gis?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory')

In [4]:
df_roads = pd.read_sql_query('select * from ventyx_may_2012.maj_road_polyline',engine_source)

In [5]:
df_roads = df_roads.set_index('gid')

In [6]:
df_roads.to_sql('maj_road_polyline', engine, schema='General_GIS_DATA', if_exists = 'replace')

In [2]:
BT_all = pd.read_csv('LEMMA_ADS_AllSpp_AlYrs_011817.csv', encoding='UTF-8', delimiter = ',')

In [ ]:


In [3]:
engine = create_engine('postgresql+pg8000://jdlara:Amadeus-2010@switch-db2.erg.berkeley.edu:5432/apl_cec?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory', isolation_level="AUTOCOMMIT")

In [4]:
BT_all.to_sql('lemma_crmort', engine, schema='lemma', if_exists = 'replace',chunksize=10000)


/Library/Python/2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:2503: SAWarning: Did not recognize type 'geometry' of column 'geom'
  (attype, name))

In [5]:
BT_all.head(5)


Out[5]:
key x y D_BM_kg relNO relBA PlotID Pol.x Pol.y RPT_YR ... Pol.Shap_Ar D_Pol_BM_kg All_BM_kgha All_Pol_BM_kgha THA QMD_DOM Av_BM_TR Pol.ID All_Pol_NO All_Pol_BM
0 1 -2219310 1956660 0.0 0.0 0.0 -265 -2.219479e+06 1.956794e+06 2015 ... 367114.455769 40491.97815 0.0 46547.327784 0.0 0.0 444.966793 1 0.0 1.537938e+09
1 2 -2219490 1956840 0.0 0.0 0.0 -265 -2.219479e+06 1.956794e+06 2015 ... 367114.455769 40491.97815 0.0 46547.327784 0.0 0.0 444.966793 1 0.0 1.537938e+09
2 3 -2219670 1956870 0.0 0.0 0.0 -265 -2.219479e+06 1.956794e+06 2015 ... 367114.455769 40491.97815 0.0 46547.327784 0.0 0.0 444.966793 1 0.0 1.537938e+09
3 4 -2219280 1956690 0.0 0.0 0.0 -265 -2.219479e+06 1.956794e+06 2015 ... 367114.455769 40491.97815 0.0 46547.327784 0.0 0.0 444.966793 1 0.0 1.537938e+09
4 5 -2219340 1956930 0.0 0.0 0.0 -265 -2.219479e+06 1.956794e+06 2015 ... 367114.455769 40491.97815 0.0 46547.327784 0.0 0.0 444.966793 1 0.0 1.537938e+09

5 rows × 21 columns


In [ ]: