Created
February 6, 2015 21:22
-
-
Save liesen/b304c13c6c3f9337b3d6 to your computer and use it in GitHub Desktop.
The most gender neutral baby names in Sweden, 2014: http://nbviewer.ipython.org/gist/liesen/b304c13c6c3f9337b3d6
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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:b699305abfb58e1129086124d9f167c3bb27677689d2f79ad36e3f03260afe59" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import pandas as pd" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# The most gender neutral baby names in Sweden, 2014\n", | |
"\n", | |
"**Name statistics from SCB (Statistics Sweden)**: http://www.statistikdatabasen.scb.se/pxweb/sv/ssd/START__BE__BE0001/BE0001T04BAr\n", | |
"\n", | |
"**Inspiration**: http://www.randalolson.com/2014/12/06/top-25-most-gender-neutral-names-in-the-u-s/" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"girls_names = pd.read_csv('girls_names_2014.csv', na_values=('..',), index_col=0)\n", | |
"boys_names = pd.read_csv('boys_names_2014.csv', na_values=('..',), index_col=0)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"names = pd.merge(pd.DataFrame(girls_names.dropna().unstack(), columns=['girls']),\n", | |
" pd.DataFrame(boys_names.dropna().unstack(), columns=['boys']),\n", | |
" how='inner', left_index=True, right_index=True)\n", | |
"names['sum'] = names.sum(axis=1)\n", | |
"names['cmp'] = (names['girls'] - names['boys']).abs()\n", | |
"names.groupby('cmp') \\\n", | |
" .apply(lambda x: x.sort('sum', ascending=False, inplace=False)) \\\n", | |
" .reset_index(level=0, drop=True)[['girls', 'boys']] \\\n", | |
" .xs(('2014',)) \\\n", | |
" .head(n=25)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>girls</th>\n", | |
" <th>boys</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>Mayar</th>\n", | |
" <td> 4</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Mino</th>\n", | |
" <td> 4</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Adama</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Alexi</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Amine</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Bille</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Bon</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Casey</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Mischa</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Sunny</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Tin</th>\n", | |
" <td> 2</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Ilon</th>\n", | |
" <td> 4</td>\n", | |
" <td> 5</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Elham</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Eris</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Frankie</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Freddie</th>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Ira</th>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Nicky</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Nicola</th>\n", | |
" <td> 3</td>\n", | |
" <td> 2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Sindre</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Teddie</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Ward</th>\n", | |
" <td> 2</td>\n", | |
" <td> 3</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Arya</th>\n", | |
" <td> 6</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Lee </th>\n", | |
" <td> 6</td>\n", | |
" <td> 4</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>Nima</th>\n", | |
" <td> 4</td>\n", | |
" <td> 6</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 3, | |
"text": [ | |
" girls boys\n", | |
"Mayar 4 4\n", | |
"Mino 4 4\n", | |
"Adama 2 2\n", | |
"Alexi 2 2\n", | |
"Amine 2 2\n", | |
"Bille 2 2\n", | |
"Bon 2 2\n", | |
"Casey 2 2\n", | |
"Mischa 2 2\n", | |
"Sunny 2 2\n", | |
"Tin 2 2\n", | |
"Ilon 4 5\n", | |
"Elham 2 3\n", | |
"Eris 2 3\n", | |
"Frankie 2 3\n", | |
"Freddie 3 2\n", | |
"Ira 3 2\n", | |
"Nicky 2 3\n", | |
"Nicola 3 2\n", | |
"Sindre 2 3\n", | |
"Teddie 2 3\n", | |
"Ward 2 3\n", | |
"Arya 6 4\n", | |
"Lee 6 4\n", | |
"Nima 4 6" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment