This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for token in doc: | |
| # check token pos | |
| if token.pos_=='NOUN': | |
| # print token | |
| print(token.text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import spacy | |
| import spacy | |
| # load english language model | |
| nlp = spacy.load('en_core_web_sm',disable=['ner','textcat']) | |
| text = "This is a sample sentence." | |
| # create spacy | |
| doc = nlp(text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import spacy | |
| from spacy import displacy | |
| doc = nlp('I read blogs') | |
| displacy.render(doc, style='dep',jupyter=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # print second chunk of data | |
| next(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| # pandas dataframe | |
| df = pd.read_csv('./Black Friday.csv', chunksize=10) | |
| # print first chunk of data | |
| next(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| file = "Greetings.txt" | |
| # generator expression | |
| lines = (line for line in open(file)) | |
| print(lines) | |
| # print lines | |
| print(next(lines)) | |
| print(next(lines)) | |
| print(next(lines)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| # list comprehension | |
| mylist = [i for i in range(10000000)] | |
| print('Size of list in memory',sys.getsizeof(mylist)) | |
| # generator expression | |
| mygen = (i for i in range(10000000)) | |
| print('Size of generator in memory',sys.getsizeof(mygen)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in squared_gen: | |
| print(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| squared_gen = (x*x for x in range(2,5)) | |
| print(squared_gen) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print(next(gen)) |