A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
| <script type="text/javascript" src="/media/uploads/publications/presidents_budget_fy2013/swfobject.js"></script> | |
| <script type="text/javascript"> | |
| // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. | |
| var swfVersionStr = "11.1.0"; | |
| // To use express install, set to playerProductInstall.swf, otherwise the empty string. | |
| var xiSwfUrlStr = "/media/uploads/publications/presidents_budget_fy2013/playerProductInstall.swf"; | |
| var flashvars = {datafile: "/media/uploads/publications/presidents_budget_fy2013/info/budget-category.txt"} | |
| var params = {}; | |
| params.quality = "high"; | |
| params.bgcolor = "#ffffff"; |
| # adopted from https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git#SetupSSHforGit-installpublickey, which was adopted from a GitHub script | |
| if [ -r ~/.profile ]; then . ~/.profile; fi | |
| case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac | |
| echo | |
| echo "Yo" | |
| echo | |
| SSH_ENV="$HOME/.ssh/environment" |
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
| import contextlib | |
| import csv | |
| import datetime as dt | |
| import json | |
| import os | |
| import pprint | |
| import subprocess | |
| import sys | |
| import tempfile | |
| from dataclasses import dataclass |
The Hubverse is in the processing of making hub data available via publicly-accessible AWS S3 buckets.
Cloud-based hubs "mirror" the data stored in a hub's GitHub repository and provide a few advantages for data consumers:
The examples here use the CDC's FluSight Forecast Hub, which is available in the following S3 bucket:
| #tabedata.txt is a file that contains the piped markdown table rows | |
| with open ('markdownrows.txt') as f: | |
| content = f.readlines() | |
| rows = [] | |
| for c in content: | |
| cells = c.split('|') | |
| cells = ['<td>{}</td>'.format(cell.strip()) for cell in cells] | |
| rows.append(cells) |
| from itertools import product | |
| import pandas as pd | |
| import numpy as np | |
| def make_sample( | |
| n_samples: int = 2, | |
| n_horizons: int = 3, | |
| n_variants: int = 3, | |
| n_locations: int = 2, | |
| samples_joint_across: list[str] = None |
| # If you come from bash you might have to change your $PATH. | |
| # export PATH=$HOME/bin:/usr/local/bin:$PATH | |
| # Path to your oh-my-zsh installation. | |
| export ZSH="/home/becky/.oh-my-zsh" | |
| # Set name of the theme to load --- if set to "random", it will | |
| # load a random theme each time oh-my-zsh is loaded, in which case, | |
| # to know which specific one was loaded, run: echo $RANDOM_THEME | |
| # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes |
| #------------------------------------------------------------------------------ | |
| # Make things VirtualEnv aware (Windows version). | |
| # More info: http://www.swegler.com/becky/blog/2011/08/28/python-django-mysql-on-windows-7-part-3-ipython-virtual-environments/ | |
| # add this to the end of ipython_config | |
| # (or course, for virtualenvs created via --no-site-packages, it would | |
| # be much easier just to install iPython) | |
| #------------------------------------------------------------------------------ | |
| import sys | |
| import site | |
| from os import environ |
| #create the database | |
| CREATE DATABASE [dbname] CHARACTER SET utf8; | |
| #create user | |
| CREATE USER 'django_user'@'localhost' IDENTIFIED BY 'thepassword'; | |
| #give user permissions to db (probably not a great idea to GRANT ALL unless you really have to) | |
| # (replace django.* with [mydatabasename].*) | |
| GRANT ALL ON django.* TO 'django_user'@'localhost'; |