names = ['Matt', 'Jane', 'Shankar', 'Ella', 'Jim', 'Aragorn'] longest_name = max(names) print(longest_name) #>>>> Shankar names_and_lengths = [(i, len(i)) for i in names] print(names_and_lengths) #>>>> [('Matt', 4), ('Jane', 4), ('Shankar', 7), ...]
conda install -c conda-forge spacy
python3 -m spacy download en
python -m spacy download en
import spacy nlp = spacy.load('en') mystr = """Creating bar charts with ambiguity and degrees of uncertainty or other variables in them might cause champions of legibility and transparency some unease.""" doc = nlp(mystr)
import pandas as pd terms = [i.text for i in doc] lemmas = [i.lemma_ for i in doc] pos_tags = [i.pos_ for i in doc] tags = [i.tag_ for i in doc] deps = [i.dep_ for i in doc] df = pd.DataFrame({"term":terms, "lemma":lemmas, "pos":pos_tags, "tag":tags, "dependency": deps}) df.iloc[:16]
spacy.explain("ADP")
text = "But Google is starting from behind. The company made \ a late push into hardware, and Apple’s Siri, available on \ iPhones, and Amazon’s Alexa software, which runs on its Echo \ and Dot devices, have clear leads in consumer adoption." doc = nlp(text) for ent in doc.ents: print(ent.text, ent.start_char, ent.end_char, ent.label_)
list(doc.noun_chunks)
import spacy from spacy import displacy nlp = spacy.load('en') doc1 = nlp(u'This is a sentence.') displacy.render(doc1, style='dep', jupyter=True)
text = "But Google is starting from behind. The company made \ a late push into hardware, and Apple’s Siri, available on \ iPhones, and Amazon’s Alexa software, which runs on its Echo \ and Dot devices, have clear leads in consumer adoption." doc = nlp(text) displacy.render(doc, style='ent', jupyter=True)