Skip to content

Instantly share code, notes, and snippets.

View kshirsagarsiddharth's full-sized avatar
🎯
Focusing

kshirsagarsiddharth

🎯
Focusing
View GitHub Profile
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Login email;Identifier;First name;Last name
laura@example.com;2070;Laura;Grey
craig@example.com;4081;Craig;Johnson
mary@example.com;9346;Mary;Jenkins
jamie@example.com;5079;Jamie;Smith
import spacy
# Load the English model
nlp = spacy.load("en_core_web_sm")
def clean_social_media_data(text):
# Process the text
doc = nlp(text)
# Extract the lemmas and remove stop words
import re
def clean_social_media_data(text):
# Remove hashtags and mentions
text = re.sub(r'#\w+', '', text)
text = re.sub(r'@\w+', '', text)
# Remove emojis
text = re.sub(r'[^\x00-\x7F]+', '', text)
import spacy
# Load the English model
nlp = spacy.load("en_core_web_sm")
def lemmatize_text(text):
# Process the text
doc = nlp(text)
# Extract the lemmas
import nltk
from nltk.stem import WordNetLemmatizer
# Initialize the lemmatizer
lemmatizer = WordNetLemmatizer()
def lemmatize_text(text):
# Tokenize the text
tokens = nltk.word_tokenize(text)
import nltk
from nltk.corpus import stopwords
# Load the stop words
stop_words = set(stopwords.words('english'))
def remove_stop_words(text):
# Tokenize the text
tokens = nltk.word_tokenize(text)
def remove_stop_words(text):
# Split the text into words
words = text.split()
# Define the stop words
stop_words = ['a', 'an', 'and', 'the', 'in', 'of']
# Remove stop words
clean_words = [word for word in words if word not in stop_words]
import re
def clean_text(text):
# Use a regular expression to remove punctuation and special characters
clean_text = re.sub(r'[^\w\s]', '', text)
# Remove leading and trailing whitespace
clean_text = clean_text.strip()
return clean_text
import string
def clean_text(text):
# Create a translation table to remove punctuation and special characters we are replacing space.
translator = str.maketrans('', '', string.punctuation + string.printable.replace(' ','')[62:])
# Use the translate method to remove the characters
clean_text = text.translate(translator)
@app.callback(Output('km-travelled-gauge', 'value'), Input('km-travelled-slider', 'value'))
def km_travelled_update(km_travelled):
return km_travelled
@app.callback(Output('km-per-liters-slider-output', 'value'), Input('km-per-liters-slider', 'value'))
def km_travelled_update(km_per_lit):
return km_per_lit
@app.callback(Output('engine-size-slider-output', 'value'), Input('engine-size-slider', 'value'))
def km_travelled_update(engine_slider):