import pandas as pd
import numpy as np
import pandas_datareader.data as web
import datetime
import matplotlib.pyplot as plt
%matplotlib inline
df=pd.read_csv('nf_complete.csv')
df.columns
Index(['Unnamed: 0', 'year', 'title', 'abstract', 'theme', 'China', 'Russia',
       'War', 'President', 'US', 'Vietnam', 'Cold War', 'World War',
       'Vietnam War', 'Korean War', 'Survey', 'Case Study', 'Trade',
       'Humanitarian', 'fixed_effects', 'instrumental_variable', 'regression',
       'experimental'],
      dtype='object')
df[["year","title"]]
year title
0 2000 "Institutions at the Domestic/International Ne...
1 2000 Born to Lose and Doomed to Survive: State Deat...
2 2000 The significance of “allegiance” in internatio...
3 2000 The significance of “allegiance” in internatio...
4 2000 Truth-Telling and Mythmaking in Post-Soviet Ru...
... ... ...
121 2018 Planning for the Short Haul: Trade Among Belli...
122 2018 Clinging to the Anti-Imperial Mantle: The Repu...
123 2018 The New Navy's Pacific Wars: Peripheral Confl...
124 2018 Stop or I'll Shoot, Comply and I Won't: The Di...
125 2018 Unexpected Humanitarians: Albania, the U.S. Mi...

126 rows × 2 columns

df_subset = df[["year", "title", "abstract", "theme", "War", 'Cold War',"Trade"]]
df_subset
year title abstract theme War Cold War Trade
0 2000 "Institutions at the Domestic/International Ne... Civil-military relations are frequently studie... IR scholarship 1 0 0
1 2000 Born to Lose and Doomed to Survive: State Deat... Under what conditions do states die, or exit t... IR scholarship 1 1 0
2 2000 The significance of “allegiance” in internatio... My dissertation employs original and secondary... IR scholarship 1 0 0
3 2000 The significance of “allegiance” in internatio... \nThis study revises prevailing interpretation... Conflit Between States 0 1 0
4 2000 Truth-Telling and Mythmaking in Post-Soviet Ru... Can distorted and pernicious ideas about histo... Conflict Between States 1 0 0
... ... ... ... ... ... ... ...
121 2018 Planning for the Short Haul: Trade Among Belli... In times of war, why do belligerents continue ... Conflict between states 1 0 1
122 2018 Clinging to the Anti-Imperial Mantle: The Repu... My dissertation project, Clinging to the Anti-... Cold War 0 1 0
123 2018 The New Navy's Pacific Wars: Peripheral Confl... Using a transnational methodology and sources ... Military History 1 0 0
124 2018 Stop or I'll Shoot, Comply and I Won't: The Di... There is a dilemma at the heart of coercion. S... IR Scholarship 0 0 1
125 2018 Unexpected Humanitarians: Albania, the U.S. Mi... Using archives and oral history, this disserta... Military History 0 0 0

126 rows × 7 columns

df_subset.columns = ["year", "title", "abstract", "theme", "War", 'Cold War',"Trade"]
df_subset
year title abstract theme War Cold War Trade
0 2000 "Institutions at the Domestic/International Ne... Civil-military relations are frequently studie... IR scholarship 1 0 0
1 2000 Born to Lose and Doomed to Survive: State Deat... Under what conditions do states die, or exit t... IR scholarship 1 1 0
2 2000 The significance of “allegiance” in internatio... My dissertation employs original and secondary... IR scholarship 1 0 0
3 2000 The significance of “allegiance” in internatio... \nThis study revises prevailing interpretation... Conflit Between States 0 1 0
4 2000 Truth-Telling and Mythmaking in Post-Soviet Ru... Can distorted and pernicious ideas about histo... Conflict Between States 1 0 0
... ... ... ... ... ... ... ...
121 2018 Planning for the Short Haul: Trade Among Belli... In times of war, why do belligerents continue ... Conflict between states 1 0 1
122 2018 Clinging to the Anti-Imperial Mantle: The Repu... My dissertation project, Clinging to the Anti-... Cold War 0 1 0
123 2018 The New Navy's Pacific Wars: Peripheral Confl... Using a transnational methodology and sources ... Military History 1 0 0
124 2018 Stop or I'll Shoot, Comply and I Won't: The Di... There is a dilemma at the heart of coercion. S... IR Scholarship 0 0 1
125 2018 Unexpected Humanitarians: Albania, the U.S. Mi... Using archives and oral history, this disserta... Military History 0 0 0

126 rows × 7 columns

import sqlalchemy as db
from sqlalchemy import create_engine
import sqlite3
import pandas as pd
engine = db.create_engine('sqlite:///nf_nlp.db')
connection = engine.connect()
metadata = db.MetaData()
nf_nlp_table = db.Table('nf_nlp_table', metadata, 
    db.Column('year',db.Integer, nullable=True, index=False),
    db.Column('title',db.String, nullable=True),
    db.Column('abstract',db.String, nullable=True),
    db.Column('theme',db.String, nullable=True),
    db.Column('War',db.Integer, nullable=True),
    db.Column('Cold War',db.Integer, nullable=True),
    db.Column('Trade', db.Integer, nullable=True)
)
metadata.create_all(engine) #Creates the table
nf_nlp_table
Table('nf_nlp_table', MetaData(bind=None), Column('year', Integer(), table=<nf_nlp_table>), Column('title', String(), table=<nf_nlp_table>), Column('abstract', String(), table=<nf_nlp_table>), Column('theme', String(), table=<nf_nlp_table>), Column('War', Integer(), table=<nf_nlp_table>), Column('Cold War', Integer(), table=<nf_nlp_table>), Column('Trade', Integer(), table=<nf_nlp_table>), schema=None)
df_subset.to_sql('nf_nlp_table', con=engine, if_exists='append', index=False)
engine.execute("SELECT year, theme, title FROM nf_nlp_table LIMIT 10").fetchall()
[(2000, 'IR scholarship', '"Institutions at the Domestic/International Nexus: the political-military  origins of military effectiveness, strategic integration and war'),
 (2000, 'IR scholarship', 'Born to Lose and Doomed to Survive: State Death and Survival in the International System'),
 (2000, 'IR scholarship', 'The significance of “allegiance” in international relations'),
 (2000, 'Conflit Between States', 'The significance of “allegiance” in international relations'),
 (2000, 'Conflict Between States', 'Truth-Telling and Mythmaking in Post-Soviet Russia: Historical Ideas, Mass Education, and Interstate Conflict'),
 (2000, 'Domestic Military History', 'Building a Cape Fear Metropolis: Fort Bragg, Fayetteville, and the  Sandhills of North Carolina'),
 (2000, 'Culture', 'The Glories and the Sadness: Shaping the national Memory of the First World War in Great Britain, Canada and Australia'),
 (2000, 'Culture / Peace Process', 'What leads longstanding adversaries to engage in conflict resolution'),
 (2001, 'Military History', 'A School for the Nation: Military  Institutions and the Boundaries of Nationality'),
 (2001, 'Military History', "The 'American Century' Army:  The Origins of the U.S. Cold War Army, 1949-1959")]
sql = """
SELECT
  year
, theme
, title
FROM nf_nlp_table
"""

cnxn = connection
df = pd.read_sql(sql, cnxn)
df.tail(30)
year theme title
96 2014 IR Scholarship “Multiparty Mediation: Identifying Characteris...
97 2014 IR Scholarship The Justice Dilemma: International Criminal Ac...
98 2014 IR Scholarship Beyond Revolution and Repression: U.S. Foreign...
99 2014 IR Scholarship Protection States Trust?: Major Power Patronag...
100 2014 Nuclear Weapons The Constraining Power of the Nuclear Nonproli...
101 2015 Military History Selling Her the Military: Recruiting Women int...
102 2015 IR Scholarship American Evangelicals, Israel, and Modern Chri...
103 2015 Non-state Who Can Keep the Peace? Insurgent Organization...
104 2015 IR Scholarship Credibility in Crisis: The Role of Leadership ...
105 2015 IR Scholarship Evaluating the Changing of the Guards: Survey ...
106 2015 Soviet Union Extracting the Eagle’s Talons: The Soviet Unio...
107 2015 IR Scholarship The Control War: Communist Revolutionary Warfa...
108 2015 Nuclear Weapons Nuclear Weapons and Foreign Policy
109 2016 Civ-Mil Securing Control and Controlling Security: Civ...
110 2016 Military History Digging for Victory: The Stalinist State’s Mob...
111 2016 Non-state Persuading Power: Insurgent Diplomacy and the ...
112 2016 Conflict between states A Prelude to Violence? The Effect of Nationali...
113 2016 Conflict between states Engaging the ‘Evil Empire’: East – West Relati...
114 2017 IR Scholarship More Talk, Less Action: Why Costless Diplomacy...
115 2017 Cold War Experiments in Peace: Asian Neutralism, Human ...
116 2017 IR Scholarship Fully Committed? Religiously Committed State P...
117 2017 Military History Straddling the Threshold of Two Worlds: Soldie...
118 2017 Military History U.S. Army’s Investigation and Adjudication of ...
119 2017 IR Scholarship Grand Strategic Crucibles: The Lasting Effects...
120 2018 Nuclear Weapons Trust in International Politics: The Role of L...
121 2018 Conflict between states Planning for the Short Haul: Trade Among Belli...
122 2018 Cold War Clinging to the Anti-Imperial Mantle: The Repu...
123 2018 Military History The New Navy's Pacific Wars: Peripheral Confl...
124 2018 IR Scholarship Stop or I'll Shoot, Comply and I Won't: The Di...
125 2018 Military History Unexpected Humanitarians: Albania, the U.S. Mi...