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 pandas as pd | |
import openpyxl as pxl | |
from openpyxl.utils.dataframe import dataframe_to_rows | |
# Name of the workbook we'll be using | |
filename = 'test_wb.xlsx' | |
# For demo purposes, create a new 1-sheet workbook | |
# DataFrame to be inserted in the first worksheet | |
firstMockDF = pd.DataFrame({ |
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 pandas as pd | |
import openpyxl as pxl | |
# DataFrame to be inserted in the first worksheet | |
firstMockData = { | |
'a': [1,2], | |
'b': [3,4] | |
} | |
firstMockDF = pd.DataFrame(firstMockData) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Login</title> | |
<link rel="stylesheet" href="login-page.css"> | |
<script defer src="login-page.js"></script> | |
</head> |
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 pandas as pd | |
import numpy as np | |
def generate_random_dates(num_dates: int) -> np.array: | |
"""Generate a 1D array of `num_dates` random dates. | |
""" | |
start_date = "2020-01-01" | |
# Generate all days for 2020 | |
available_dates = [np.datetime64(start_date) + days for days in range(365)] | |
# Get `num_dates` random dates from 2020 |
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
# Pivot the DF so that there's a column for each month, each row\ | |
# represents a year, and the cells have the mean page views for the\ | |
# respective year and month | |
df_pivot = pd.pivot_table( | |
df, | |
values="page_views", | |
index="year", | |
columns="month", | |
aggfunc=np.mean | |
) |
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 pandas as pd | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Load the CSV (load date data as proper date types) | |
df = pd.read_csv("page_views.csv") | |
df["date"] = pd.to_datetime(df["date"]) | |
# Sort the DF from oldest to most recent recordings | |
df.sort_values(by="date", inplace=True) | |
# Use the column of dates as the DF's index |
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
html { | |
height: 100%; | |
} | |
body { | |
height: 100%; | |
margin: 0; | |
font-family: Arial, Helvetica, sans-serif; | |
display: grid; | |
justify-items: center; |
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 pandas_datareader import data as web | |
def download_data(tickers, start_date, end_date): | |
for ticker in tickers: | |
try: | |
print(f'Downloading {ticker}') | |
# Download data from Yahoo | |
temp_df = web.DataReader(ticker, 'yahoo', start_date, end_date) | |
# Create a column with only the ticker symbol | |
temp_df["Ticker"] = ticker |
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 pygame | |
from random import randint, choice | |
# RGB colours | |
BLACK = (0, 0,0) | |
WHITE = (255, 255, 255) | |
GREEN = (44, 205, 23) | |
RED = (216, 10, 0) | |
BLUE = (27, 64, 255) | |
PURPLE = (121, 0, 234) |
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 PIL import Image, ImageDraw, ImageFont | |
from textwrap import wrap | |
def get_y_and_heights(text_wrapped, dimensions, margin, font): | |
"""Get the first vertical coordinate at which to draw text and the height of each line of text""" | |
# https://stackoverflow.com/a/46220683/9263761 | |
ascent, descent = font.getmetrics() | |
# Calculate the height needed to draw each line of text (including its bottom margin) | |
line_heights = [ |
NewerOlder