Skip to content

Instantly share code, notes, and snippets.

# Licensed under the MIT License. See comment below for full licence information.
import pandas as pd
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
## data processing
df = pd.read_csv("data.csv")
df = df[ df['Value'] > 0]
@ChadThackray
ChadThackray / gridtraveller.py
Last active June 22, 2024 09:16
Recursion and memoisation in python with the gridTraveller problem
# Licensed under the MIT License. See comment below for full licence information.
def gridtraveller(m,n, dict = {}):
key = str(m) + "," + str(n)
if(m == 1 and n == 1):
return 1
elif(m ==0 or n == 0):
return 0
elif( key in dict.keys()):
@ChadThackray
ChadThackray / menus.py
Created June 20, 2024 18:01
Simple menus in python
# Licensed under the MIT License. See comment below for full license information.
from simple_term_menu import TerminalMenu
options = ["[a] Apples","[b] Bannas","[o] Oranges","[q] Quit"]
mainMenu = TerminalMenu(options, title = "main menu")
subMenu = TerminalMenu(["option1","option2"], title = "sub-menu")
quitting = False
@ChadThackray
ChadThackray / yfinance.py
Created June 20, 2024 17:35
Yahoo finance stock data in python with yfinance
# Licensed under the MIT License. See comment below for full license information.
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
stock = yf.Ticker("KO")
print(stock.info['open'])
@ChadThackray
ChadThackray / video-code.py
Last active June 22, 2024 09:13
Historical bitcoin charts in python (Bitcoin data science #1)
# Licensed under the MIT License. See comment below for full license information.
import matplotlib.pyplot as plt
import pandas as pd
plt.style.use("dark_background")
df = pd.read_csv("Kraken_BTCUSD_d.csv")
@ChadThackray
ChadThackray / code.py
Last active August 13, 2024 19:25
Get live cryptocurrency prices in python
# Licensed under the MIT License. See comment below for full licence information.
import requests
import json
bob = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=gbp", headers = {"accept":"application/json"})
print("The price of bitcoin is currently £" + str(bob.json()["bitcoin"]["gbp"]))