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 matplotlib.colors import LinearSegmentedColormap | |
bins = [0,1] | |
# Maps values to a bin. | |
# The mapped values must start at 0 and end at 1. | |
def bin_mapping(x): | |
for idx, bound in enumerate(bins): | |
if x < bound: | |
return idx / (len(bins) - 1.0) |
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
def zptile(z_score): | |
return .5 * (math.erf(z_score / 2 ** .5) + 1) | |
zptile(0.95) | |
# excel says: 0.8289438737 | |
0.8289438736915181 | |
via: http://stackoverflow.com/questions/2782284/function-to-convert-a-z-score-into-a-percentage |
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
SELECT dob, SUBSTRING_INDEX( `dob` , '/', 1 ) AS mo, | |
SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 2 ),'/',-1) AS dy, | |
SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 3 ),'/',-1) AS yr, | |
CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 3 ),'/',-1),"-",SUBSTRING_INDEX( `dob` , '/', 1 ),"-",SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 2 ),'/',-1)) AS dt | |
FROM table | |
"dob" "mo" "dy" "yr" "dt" | |
"7/19/1970" "7" "19" "1970" "1970-7-19" |
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
2010-2014, ACS 5-year sample | |
Source: IPUMS.org | |
Nativer American Alone, by Tribal Identification | |
302: Apache 70,940 | |
303: Blackfoot 28,256 | |
304: Cherokee 279,721 | |
305: Cheyenne 14,386 | |
306: Chickasaw 23,110 | |
307: Chippewa 114,423 |
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
The correct 'link': | |
<div class='map-navigation' data-zoom='12' data-position='<%=d.tractlat%>,<%=d.tractlon%>'>Zoom</div> | |
The 'link' that zoomed but then reloaded page: | |
<div class='map-navigation'><a href='' data-zoom='12' data-position='<%=d.tractlat%>,<%=d.tractlon%>'>Zoom</a></div> | |
The zoomer function: | |
document.querySelector('.map-navigation').onclick = function(abc) { | |
var pos = abc.target.getAttribute('data-position'); | |
var zoom = abc.target.getAttribute('data-zoom'); |
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
Bonus example: | |
The IPUMS SDA query interface allows you to collapse variables into broader categories. I do this often with occupations -- individual occupations are usually too small to carry a meaningful sample size, but if you look at the occupational hierarchy in the docs, you can see how you might tile up individual occupations into broader but still meaningful categories. | |
So try this. | |
1) Pick any sample to query | |
2) put sex as your column |
NewerOlder