Skip to main content

converts a spaCy object into a pandas DataFrame

Project description

converts a spaCy object into a pandas DataFrame

pip install spacy2df

Tested against Windows 10 / Python 3.10 / Anaconda

import spacy
from spacy2df import spacy2df

# Load Spacy model and create a doc object
nlp = spacy.load(pt_core_news_sm)
frase = Rede do Banco Itaú é bom
doc = nlp(frase)

# Convert the doc object to a DataFrame
df = spacy2df(doc, colprefix='aa_')
print(df)

                  aa_dep                    aa_doc aa_ent_id aa_ent_iob aa_ent_kb_id aa_ent_type  aa_has_vector aa_head  aa_is_alpha  aa_is_ascii  aa_is_bracket  aa_is_currency  aa_is_digit  aa_is_left_punct  aa_is_lower  aa_is_oov  aa_is_punct  aa_is_quote  aa_is_right_punct  aa_is_sent_end  aa_is_sent_start  aa_is_space  aa_is_stop  aa_is_title  aa_is_upper aa_lang aa_left_edge aa_lemma  aa_like_email  aa_like_num  aa_like_url aa_lower  aa_n_lefts  aa_n_rights                                                                              aa_morph aa_norm aa_orth aa_pos aa_prefix               aa_rank aa_right_edge                          aa_sent aa_sent_start  aa_sentiment aa_shape aa_suffix aa_tag        aa_ancestors aa_children   aa_lefts aa_rights                       aa_subtree aa_iob_strings morph_Gender morph_Number morph_Definite morph_PronType morph_Mood  morph_Person morph_Tense morph_VerbForm
    0      nsubj  Rede do Banco Itaú é bom                    O                                    True     bom         True         True          False           False        False             False        False       True        False        False              False           False              True        False       False         True        False      pt         Rede     rede          False        False        False     rede           0         True                                                   {'Gender' 'Fem', 'Number' 'Sing'}    rede    Rede  PROPN         R  18446744073709551615          Itaú  (Rede, do, Banco, Itaú, é, bom)         False           0.0     Xxxx       ede  PROPN              (bom,)    (Banco,)         ()  (Banco,)          (Rede, do, Banco, Itaú)    (, I, O, B)          Fem         Sing           NA           NA       NA          NA        NA           NA
    1       case  Rede do Banco Itaú é bom                    O                                    True   Banco         True         True          False           False        False             False         True       True        False        False              False           False             False        False        True        False        False      pt           do     de o          False        False        False       do           0        False            {'Definite' 'Def', 'Gender' 'Masc', 'Number' 'Sing', 'PronType' 'Art'}      do      do    ADP         d  18446744073709551615            do  (Rede, do, Banco, Itaú, é, bom)            -1           0.0       xx        do    ADP  (Banco, Rede, bom)          ()         ()        ()                            (do,)    (, I, O, B)         Masc         Sing            Def            Art       NA          NA        NA           NA
    2       nmod  Rede do Banco Itaú é bom                    B                      LOC           True    Rede         True         True          False           False        False             False        False       True        False        False              False           False             False        False       False         True        False      pt           do    Banco          False        False        False    banco           1         True                                                  {'Gender' 'Masc', 'Number' 'Sing'}   banco   Banco  PROPN         B  18446744073709551615          Itaú  (Rede, do, Banco, Itaú, é, bom)            -1           0.0    Xxxxx       nco  PROPN         (Rede, bom)  (do, Itaú)      (do,)   (Itaú,)                (do, Banco, Itaú)    (, I, O, B)         Masc         Sing           NA           NA       NA          NA        NA           NA
    3  flatname  Rede do Banco Itaú é bom                    I                      LOC           True   Banco         True        False          False           False        False             False        False       True        False        False              False           False             False        False       False         True        False      pt         Itaú     Itaú          False        False        False     itaú           0        False                                                                    {'Number' 'Sing'}    itaú    Itaú  PROPN         I  18446744073709551615          Itaú  (Rede, do, Banco, Itaú, é, bom)            -1           0.0     Xxxx       taú  PROPN  (Banco, Rede, bom)          ()         ()        ()                          (Itaú,)    (, I, O, B)         NA         Sing           NA           NA       NA          NA        NA           NA
    4        cop  Rede do Banco Itaú é bom                    O                                    True     bom         True        False          False           False        False             False         True       True        False        False              False           False             False        False        True        False        False      pt            é      ser          False        False        False        é           0        False  {'Mood' 'Ind', 'Number' 'Sing', 'Person' '3', 'Tense' 'Pres', 'VerbForm' 'Fin'}       é       é    AUX         é  18446744073709551615             é  (Rede, do, Banco, Itaú, é, bom)            -1           0.0        x         é    AUX              (bom,)          ()         ()        ()                             (é,)    (, I, O, B)         NA         Sing           NA           NA        Ind             3        Pres            Fin
    5       ROOT  Rede do Banco Itaú é bom                    O                                    True     bom         True         True          False           False        False             False         True       True        False        False              False            True             False        False        True        False        False      pt         Rede      bom          False        False        False      bom           2        False                                                  {'Gender' 'Masc', 'Number' 'Sing'}     bom     bom    ADJ         b  18446744073709551615           bom  (Rede, do, Banco, Itaú, é, bom)            -1           0.0      xxx       bom    ADJ                  ()   (Rede, é)  (Rede, é)        ()  (Rede, do, Banco, Itaú, é, bom)    (, I, O, B)         Masc         Sing           NA           NA       NA          NA        NA           NA

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacy2df-0.10.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distribution

spacy2df-0.10-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page