In [1]:
import glob
from io import open
import bibtexparser
from bibtexparser.bparser import BibTexParser
import pandas as pd
from pandas import DataFrame as df
from os import path
from bs4 import BeautifulSoup

In [37]:
import matplotlib.pyplot as plt
%matplotlib inline

In [33]:
citations = []
for file in glob.glob("*html"):
  word = path.basename(file).split('.')[0]
  html = BeautifulSoup(open(file).read())
  for paper in soup.findAll('dl', attrs={"class": "print-citation"}):
    fields = [x.text for x in p0.findAll('dt', attrs={"data-auto": "citation_field_label"})]
    values = [x.text for x in p0.findAll('dd', attrs={"data-auto": "citation_field_value"})]
    citation = dict(zip(fields, values))
    citation["word"] = word
    citations.append(citation)
df.from_dict(citations)


Out[33]:
Abstract: Accession Number: Authors: Document Type: Format Covered: ISBN: Intended Audience: Keywords: Language: Location: Page Count: Population: PsycINFO Classification: Publication Type: Release Date: Source: Subjects: Title: UR: word
0 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
1 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
2 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
3 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
4 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
5 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic
6 This\n chapter discusses mixed-race in the dec... 2014-20689-010 Aspinall, Peter J., University of Kent, Canter... Chapter Print 978-0-8147-7073-3 (Hardcover)978-0-8147-8915-5... Psychology: Professional & Research (PS) mixed-race, globalization, super-diversity, et... English England; Wales 25 Human Culture & Ethnology (2930) Book; Edited Book 20140929 Global\n mixed race. King-O'Riain, Rebecca C. ... *Ethnic Identity; *Globalization; *Interethnic... Capturing\n 'mixed race' in the decennial UK c... https://libproxy-cc-stonybrook-edu.proxy.libra... polyethnic

In [32]:
words_df.to_csv("psychinfo_combined.csv", encoding='utf-8')

Load PsychINFO unified database


In [48]:
psychinfo = df.from_csv("psychinfo_combined.csv", encoding='utf-8')

In [58]:
_ = psychinfo[['word', 'year']].hist(figsize=(18,12), by='word')