Skip to content

Instantly share code, notes, and snippets.

import tabula
pdf_path = "https://github.com/chezou/tabula-py/raw/master/tests/resources/data.pdf"
dfs = tabula.read_pdf(pdf_path, stream=True)
# read_pdf returns list of DataFrames
print(len(dfs))
dfs[0]
import calendar
print(calendar.month(2020, 10))
#Save the model using pickle
import pickle
# save the model to disk
pickle.dump(model, open(model_file_path, 'wb'))
#Load the model
model = pickle.load(open(model_file_path, 'rb'))
#Saving a Keras model
# Calling `save('my_model')` creates a SavedModel folder `my_model`.
import pandas as pd
import numpy as np
df = pd.DataFrame({'city':['Sunnyvale','Palo Alto','SanFrancisco'],
'day1':[73,80,70],
'day2':[80,75,65],
'day3':[88,76,60],
'day4':[85,80,65],
'day5':[80,75,60]})
df
df.melt(id_vars=['city'])
from datetime import datetime
import pandas_datareader.data as wb
stocks = ['AAPL','GOOG','FB','AMZN','TSLA']
start = datetime(2020,9,1)
end = datetime(2020,9,30)
p = wb.DataReader(stocks, 'yahoo',start,end)
import requests
TWITTER_KEY = 'Your twitter key'
TWITTER_SECRET_KEY = 'Your secret key'
# Authenticate
auth = tweepy.AppAuthHandler(TWITTER_KEY, TWITTER_SECRET_KEY)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
# Flickr API - to extract the pictures containing giraffe and geo location
# insert your own key and secret
api_key = 'bb442da9177b0f782255e227f2f2cee4'
secret_api_key ='4cf09aea38529025'
fr = flickrapi.FlickrAPI(api_key, secret_api_key)
pset_id = '72157673330147052'
for photo in fr.walk_set(photoset_id=pset_id, extras="geo"):
print (photo.attrib['id'])
import tensorflow as tf
# Call back class
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if(logs.get('accuracy')>0.8):
print("\nReached 80% accuracy so cancelling training!")
self.model.stop_training = True
mnist = tf.keras.datasets.fashion_mnist
import feedparser
import pandas as pd
class WhizRssAggregator():
feedurl = ""
#global df
#df = pd.DataFrame(columns=['title', 'link', 'decription','published', 'content'])
def __init__(self, paramrssurl):
#Sample code to use the google API
from google.cloud import vision
from google.cloud.vision import types
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "keyFile.json"
def vision(url):
image = types.Image()
image.source.image_uri = url