In [2]:
import pandas as pd
GenesisDF = pd.read_excel("GenesisDF.xlsx")
from spacy.en import English
nlp = English()

In [3]:
del GenesisDF['link']
del GenesisDF['Unnamed: 0']

In [4]:
GenesisDF['NamedEntiryRecognition']=GenesisDF['passageText'].apply(lambda x: nlp(x).ents)

In [5]:
GenesisDF.head()


Out[5]:
passage passageText NamedEntiryRecognition
0 Genesis1:1 b'In the beginning God created the heaven and ... ()
1 Genesis1:2 b'And the earth was without form, and void; an... ()
2 Genesis1:3 b'And God said, Let there be light: and there ... ()
3 Genesis1:4 b'And God saw the light, that it was good: and... ()
4 Genesis1:5 b'And God called the light Day, and the darkne... ((Night), (first ))

In [6]:
def getNounChunks(x):
    chunksList = []
    for chunk in nlp(x).noun_chunks:
        chunksList.append(chunk)
    return chunksList

In [7]:
GenesisDF['NounChunks'] = GenesisDF['passageText'].apply(lambda x: getNounChunks(x))

In [8]:
GenesisDF.head(10)


Out[8]:
passage passageText NamedEntiryRecognition NounChunks
0 Genesis1:1 b'In the beginning God created the heaven and ... () [(God ), (the , heaven ), (the , earth)]
1 Genesis1:2 b'And the earth was without form, and void; an... () [(the , earth ), (form), (darkness ), (the , f...
2 Genesis1:3 b'And God said, Let there be light: and there ... () [(b'And ), (God ), (light), (light)]
3 Genesis1:4 b'And God saw the light, that it was good: and... () [(God ), (the , light), (it ), (God ), (the , ...
4 Genesis1:5 b'And God called the light Day, and the darkne... ((Night), (first )) [(God ), (the , light , Day), (he ), (the , ev...
5 Genesis1:6 b'And God said, Let there be a firmament in th... () [(b'And ), (God ), (a , firmament ), (the , mi...
6 Genesis1:7 b'And God made the firmament, and divided the ... () [(God ), (the , firmament), (the , waters ), (...
7 Genesis1:8 b'And God called the firmament Heaven. And the... ((second ),) [(God ), (the , firmament ), (the , evening ),...
8 Genesis1:9 b'And God said, Let the waters under the heave... ((one ),) [(b'And ), (God ), (the , waters ), (the , hea...
9 Genesis1:10 b'And God called the dry land Earth; and the g... ((Earth),) [(b'And ), (God ), (the , dry , land ), (the ,...

In [9]:
def getNSubj(x):
    NSubjList = []
    doc = nlp(x)
    for token in doc:
        if token.dep_ == 'nsubj':
            NSubjList.append(token)
    return NSubjList

In [10]:
GenesisDF['NSubjs'] = GenesisDF['passageText'].apply(lambda x: getNSubj(x))

In [11]:
GenesisDF.head(10)


Out[11]:
passage passageText NamedEntiryRecognition NounChunks NSubjs
0 Genesis1:1 b'In the beginning God created the heaven and ... () [(God ), (the , heaven ), (the , earth)] [God ]
1 Genesis1:2 b'And the earth was without form, and void; an... () [(the , earth ), (form), (darkness ), (the , f... [earth , darkness , Spirit ]
2 Genesis1:3 b'And God said, Let there be light: and there ... () [(b'And ), (God ), (light), (light)] [God ]
3 Genesis1:4 b'And God saw the light, that it was good: and... () [(God ), (the , light), (it ), (God ), (the , ... [b'And , God , it , God ]
4 Genesis1:5 b'And God called the light Day, and the darkne... ((Night), (first )) [(God ), (the , light , Day), (he ), (the , ev... [God , he , evening ]
5 Genesis1:6 b'And God said, Let there be a firmament in th... () [(b'And ), (God ), (a , firmament ), (the , mi... [God , it ]
6 Genesis1:7 b'And God made the firmament, and divided the ... () [(God ), (the , firmament), (the , waters ), (... [b'And , God , which , which , it ]
7 Genesis1:8 b'And God called the firmament Heaven. And the... ((second ),) [(God ), (the , firmament ), (the , evening ),... [God , evening ]
8 Genesis1:9 b'And God said, Let the waters under the heave... ((one ),) [(b'And ), (God ), (the , waters ), (the , hea... [God , land , it ]
9 Genesis1:10 b'And God called the dry land Earth; and the g... ((Earth),) [(b'And ), (God ), (the , dry , land ), (the ,... [b'And , God , he , God , it ]

In [14]:
GenesisDF.to_excel("Visualize_Genesis.xls")


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-14-69543d5aa205> in <module>()
----> 1 GenesisDF.to_excel("Visualize_Genesis.xls")

/Library/Python/2.7/site-packages/pandas/core/frame.pyc in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep)
   1272         formatted_cells = formatter.get_formatted_cells()
   1273         excel_writer.write_cells(formatted_cells, sheet_name,
-> 1274                                  startrow=startrow, startcol=startcol)
   1275         if need_save:
   1276             excel_writer.save()

/Library/Python/2.7/site-packages/pandas/io/excel.pyc in write_cells(self, cells, sheet_name, startrow, startcol)
   1216                 wks.write(startrow + cell.row,
   1217                           startcol + cell.col,
-> 1218                           val, style)
   1219 
   1220     @classmethod

/Library/Python/2.7/site-packages/xlwt/Worksheet.pyc in write(self, r, c, label, style)
   1086            :class:`~xlwt.Style.XFStyle` object.
   1087         """
-> 1088         self.row(r).write(c, label, style)
   1089 
   1090     def write_rich_text(self, r, c, rich_text_list, style=Style.default_style):

/Library/Python/2.7/site-packages/xlwt/Row.pyc in write(self, col, label, style)
    256             self.insert_cell(col, FormulaCell(self.__idx, col, style_index, label))
    257         elif isinstance(label, (list, tuple)):
--> 258             self.__rich_text_helper(col, label, style, style_index)
    259         else:
    260             raise Exception("Unexpected data type %r" % type(label))

/Library/Python/2.7/site-packages/xlwt/Row.pyc in __rich_text_helper(self, col, rich_text_list, style, style_index)
    282                 font = self.__parent_wb.add_font(data[1])
    283             else:
--> 284                 raise Exception ("Unexpected data type %r" % type(data))
    285             if s:
    286                 rt.append((s, font))

Exception: Unexpected data type <type 'spacy.tokens.span.Span'>

In [ ]: