Skip to content

Instantly share code, notes, and snippets.

@SouravJohar
SouravJohar / data.csv
Created January 3, 2022 21:38
Sample CSV file
name value
Locke 4
Reyes 8
Ford 15
Jarrah 16
Shephard 23
Kwon 42
users = {}
for i in range(len(df)):
user_id = df.iloc[i].user_id
if user_id not in users:
users[user_id] = 1
else:
users[user_id] += 1
num_recipes_range = (100,500)
import pytesseract
import os
import sys
def read_image(img_path, lang='eng'):
"""
Performs OCR on a single image
:img_path: str, path to the image file

Hi There

pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
1 1 Allen, Miss. Elisabeth Walton female 29 0 0 24160 211.3375 B5 S 2 St Louis, MO
1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.5500 C22 C26 S 11 Montreal, PQ / Chesterville, ON
1 0 Allison, Miss. Helen Loraine female 2 1 2 113781 151.5500 C22 C26 S Montreal, PQ / Chesterville, ON
1 0 Allison, Mr. Hudson Joshua Creighton male 30 1 2 113781 151.5500 C22 C26 S 135 Montreal, PQ / Chesterville, ON
1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25 1 2 113781 151.5500 C22 C26 S Montreal, PQ / Chesterville, ON
1 1 Anderson, Mr. Harry male 48 0 0 19952 26.5500 E12 S 3 New York, NY
1 1 Andrews, Miss. Kornelia Theodosia female 63 1 0 13502 77.9583 D7 S 10 Hudson, NY
1 0 Andrews, Mr. Thomas Jr male 39 0 0 112050 0.0000 A36 S Belfast, NI
1 1 Appleton, Mrs. Edward Dale (Charlotte Lamson) female 53 2 0 11769 51.4792 C101 S D Bayside, Queens, NY
'''
Note: Using Python 2 may result in unicode errors
'''
import sys
import requests
from bs4 import BeautifulSoup as bs
url = "https://www.dictionary.com/browse/"
@SouravJohar
SouravJohar / detector.py
Last active June 21, 2023 12:12
Code for building a spam filtering bot.
import cPickle as c
import os
from sklearn import *
from collections import Counter
def load(clf_file):
with open(clf_file) as fp:
clf = c.load(fp)
return clf
from __future__ import division # only for Python 2
from sklearn import datasets
from sklearn import svm
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split as tts
from sklearn.metrics import accuracy_score
wine = datasets.load_wine()