Text Length 319065 | Keywords Count 47326 |
---|---|
FlashText | 156 ms per loop |
Compiled Regex | 19.5 s per loop |
π¨βπ»
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
# pip install flashtext | |
from flashtext.keyword import KeywordProcessor | |
keyword_processor = KeywordProcessor() | |
keyword_processor.add_keyword('Big Apple', 'New York') | |
keyword_processor.add_keyword('Bay Area') | |
keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.') | |
keywords_found | |
# ['New York', 'Bay Area'] |
This file contains 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
from flashtext.keyword import KeywordProcessor | |
keyword_processor = KeywordProcessor() | |
keyword_processor.add_keyword('Big Apple', 'New York') | |
keyword_processor.add_keyword('New Delhi', 'NCR region') | |
new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.') | |
new_sentence | |
# 'I love New York and NCR region.' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 re | |
import string | |
text_translator = str.maketrans({ord(c): " " for c in string.punctuation}) | |
def clean_text(text, remove_punctuation_all=False): | |
if not text: | |
return '' | |
try: | |
text = text.replace(chr(160), " ") | |
text = ''.join([i if ord(i) < 128 else ' ' for i in text]) |
This file contains 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
# part solution to http://stackoverflow.com/questions/41447277/trouble-using-pandas-read-html/41447560#41447560 | |
max_value = [0,0] | |
for item in [(int(val.split('/')[0]), int(val.split('/')[1])) for val in df['Date Posted'].values]: | |
if item[0] > max_value[0]: | |
max_value[0] = item[0] | |
elif item[0] == max_value[0]: | |
if item[1] > max_value[1]: | |
max_value[1] = item[1] | |
max_date_posted = str(max_value[0]) + '/' + str(max_value[1]) |
This file contains 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
# this is just to check db connection and sql commands from python. | |
# I know a better thing to do is to use django or SQLAlchemy to avoid sql injections. And that's what i do generally. | |
import sqlite3 | |
conn = sqlite3.connect('example.db') | |
conn.execute('''CREATE TABLE COMPANY | |
(ID INT PRIMARY KEY NOT NULL, | |
NAME TEXT NOT NULL, |
This file contains 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
from tkinter import* | |
class hunterClass: | |
def BMHunter(self): | |
hunter = Tk() | |
hunter.title("Beast Mastery Gear Worth Calculator") | |
agiString = StringVar() |
This file contains 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 requests | |
import json | |
resp = requests.post('https://api.thingspeak.com/update.json', | |
data=json.dumps({"api_key":"XXXXXXXXXXXXXXXX", | |
"field1":73, | |
"field2":66})) |