A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| library(httr) | |
| library(magick) | |
| library(hrbrthemes) | |
| library(ggplot2) | |
| theme_tweet_rc <- function(grid = "XY", style = c("stream", "card"), retina=FALSE) { | |
| style <- match.arg(tolower(style), c("stream", "card")) | |
| switch( |
| class MyStreamListener(tweepy.StreamListener): | |
| def __init__(self, api=None): | |
| super(MyStreamListener, self).__init__() | |
| self.num_tweets = 0 | |
| self.file = open("tweets.txt", "w") | |
| def on_status(self, status): | |
| tweet = status._json | |
| self.file.write( json.dumps(tweet) + '\n' ) | |
| self.num_tweets += 1 |
| library(idbr) # devtools::install_github('walkerke/idbr') | |
| library(ggplot2) | |
| library(animation) | |
| library(dplyr) | |
| library(ggthemes) | |
| idb_api_key("Your Census API key goes here") | |
| male <- idb1('JA', 2010:2050, sex = 'male') %>% | |
| mutate(POP = POP * -1, |
| import os | |
| from subprocess import check_call | |
| def post_save(model, os_path, contents_manager): | |
| """post-save hook for converting notebooks to .py and .html files.""" | |
| if model['type'] != 'notebook': | |
| return # only do this for notebooks | |
| d, fname = os.path.split(os_path) | |
| check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d) | |
| check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d) |
| Code Complete by Steve McConnell | |
| Jeff Atwood (Coding Horror) | |
| https://blog.codinghorror.com/code-reviews-just-do-it/ | |
| Measuring Defect Potentials and Defect Removal Efficiency | |
| http://rbcs-us.com/site/assets/files/1337/measuring-defect-potentials-and-defect-removal-efficiency.pdf | |
| Expectations, Outcomes, and Challenges Of Modern Code Review | |
| https://www.microsoft.com/en-us/research/publication/expectations-outcomes-and-challenges-of-modern-code-review/ |
| library(rvest) | |
| library(magrittr) | |
| library(dplyr) | |
| library(purrr) | |
| library(lubridate) | |
| library(tidyr) | |
| library(ggplot2) | |
| library(scales) | |
| setwd("...working directory...") |
| #SCRIPT_REAL is a function in Tableau which returns a result from an external service script. It's in this function we pass the python code. | |
| SCRIPT_REAL("from nltk.sentiment import SentimentIntensityAnalyzer | |
| text = _arg1 #you have to use _arg1 to reference the data column you're analyzing, in this case [Word]. It gets word further down after the , | |
| scores = [] #this is a python list where the scores will get stored | |
| sid = SentimentIntensityAnalyzer() #this is a class from the nltk (Natural Language Toolkit) library. We'll pass our words through this to return the score | |
| for word in text: # this loops through each row in the column you pass via _arg1; in this case [Word] | |
| ss = sid.polarity_scores(word) #passes the word through the sentiment analyzer to get the score |
| ############################################################################### | |
| # Batch script for setting up fun Python libraries for Computational Methods in the Civic Sphere 2017 | |
| # | |
| # Should be run after installing Anaconda 4.2+/Python 3.5+ via https://www.continuum.io/downloads | |
| # | |
| # Doesn't include libraries that are installed as dependencies (e.g. numpy via pandas) | |
| ############################################################################## | |
| ############################################################################## | |
| ###### Yes |
| import pandas as pd | |
| import time | |
| from nltk.sentiment import SentimentIntensityAnalyzer | |
| t0 = time.time() | |
| top_100 = pd.read_csv('/Users/brit.cava/Desktop/TabPy/top100.csv') | |
| text = top_100['Word'] | |
| sid = SentimentIntensityAnalyzer() |