Last active
February 8, 2018 19:15
-
-
Save aborruso/64673765b0bcac92c41120ff98c40c34 to your computer and use it in GitHub Desktop.
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "tydyDebby.ipynb", | |
"version": "0.3.2", | |
"views": {}, | |
"default_view": {}, | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python2", | |
"display_name": "Python 2" | |
} | |
}, | |
"cells": [ | |
{ | |
"metadata": { | |
"id": "uJhfKWBlqy3W", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"import pandas as pd\n", | |
"url='https://rawgit.com/aborruso/093df8530cbc60c88f8ac4fb32f06b47/raw/fbafb7a3033e63686dbdee7d50fe43ea4918bc5a/data.csv'" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "oxzyP3GRrUFG", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"df=pd.read_csv(url,header=None)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "0Y0uHr9Srg2S", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
}, | |
"output_extras": [ | |
{ | |
"item_id": 1 | |
} | |
], | |
"base_uri": "https://localhost:8080/", | |
"height": 175 | |
}, | |
"outputId": "73173783-6a2c-4873-dd49-56567d2726e3", | |
"executionInfo": { | |
"status": "ok", | |
"timestamp": 1518117277974, | |
"user_tz": -60, | |
"elapsed": 786, | |
"user": { | |
"displayName": "Andrea Borruso", | |
"photoUrl": "//lh4.googleusercontent.com/-RQTYEtcmSq8/AAAAAAAAAAI/AAAAAAAAgjw/xMY6SwF49C0/s50-c-k-no/photo.jpg", | |
"userId": "116128232873038517443" | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"df" | |
], | |
"execution_count": 45, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" <th>4</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>Milano</td>\n", | |
" <td>a</td>\n", | |
" <td>Deborah</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>Palermo</td>\n", | |
" <td>c</td>\n", | |
" <td>Aru</td>\n", | |
" <td>fg</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>Torino</td>\n", | |
" <td>l</td>\n", | |
" <td>ci</td>\n", | |
" <td>po</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Cardiff</td>\n", | |
" <td>g</td>\n", | |
" <td>scrive</td>\n", | |
" <td>tt</td>\n", | |
" <td>l</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3 4\n", | |
"0 Milano a Deborah NaN NaN\n", | |
"1 Palermo c Aru fg NaN\n", | |
"2 Torino l ci po NaN\n", | |
"3 Cardiff g scrive tt l" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 45 | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "YDrgW87TtEbg", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"tydyDebby=df.melt(id_vars=[0],value_name='valori',var_name = 'colonna')" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "EkMVg0WHyBsG", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
}, | |
"output_extras": [ | |
{ | |
"item_id": 1 | |
} | |
], | |
"base_uri": "https://localhost:8080/", | |
"height": 426 | |
}, | |
"outputId": "4bc4fc41-62da-4041-988b-be2aac77fe85", | |
"executionInfo": { | |
"status": "ok", | |
"timestamp": 1518117306721, | |
"user_tz": -60, | |
"elapsed": 728, | |
"user": { | |
"displayName": "Andrea Borruso", | |
"photoUrl": "//lh4.googleusercontent.com/-RQTYEtcmSq8/AAAAAAAAAAI/AAAAAAAAgjw/xMY6SwF49C0/s50-c-k-no/photo.jpg", | |
"userId": "116128232873038517443" | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"tydyDebby.rename(columns = {0:'nome'}, inplace=True)\n", | |
"tydyDebby.dropna(inplace=True,how='any')\n", | |
"tydyDebby" | |
], | |
"execution_count": 48, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>nome</th>\n", | |
" <th>colonna</th>\n", | |
" <th>valori</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>Milano</td>\n", | |
" <td>1</td>\n", | |
" <td>a</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>Palermo</td>\n", | |
" <td>1</td>\n", | |
" <td>c</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>Torino</td>\n", | |
" <td>1</td>\n", | |
" <td>l</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Cardiff</td>\n", | |
" <td>1</td>\n", | |
" <td>g</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>Milano</td>\n", | |
" <td>2</td>\n", | |
" <td>Deborah</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>Palermo</td>\n", | |
" <td>2</td>\n", | |
" <td>Aru</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>Torino</td>\n", | |
" <td>2</td>\n", | |
" <td>ci</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>Cardiff</td>\n", | |
" <td>2</td>\n", | |
" <td>scrive</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>Palermo</td>\n", | |
" <td>3</td>\n", | |
" <td>fg</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>Torino</td>\n", | |
" <td>3</td>\n", | |
" <td>po</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>Cardiff</td>\n", | |
" <td>3</td>\n", | |
" <td>tt</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td>Cardiff</td>\n", | |
" <td>4</td>\n", | |
" <td>l</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" nome colonna valori\n", | |
"0 Milano 1 a\n", | |
"1 Palermo 1 c\n", | |
"2 Torino 1 l\n", | |
"3 Cardiff 1 g\n", | |
"4 Milano 2 Deborah\n", | |
"5 Palermo 2 Aru\n", | |
"6 Torino 2 ci\n", | |
"7 Cardiff 2 scrive\n", | |
"9 Palermo 3 fg\n", | |
"10 Torino 3 po\n", | |
"11 Cardiff 3 tt\n", | |
"15 Cardiff 4 l" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 48 | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "KNcxp6uPzTiQ", | |
"colab_type": "code", | |
"colab": { | |
"autoexec": { | |
"startup": false, | |
"wait_interval": 0 | |
} | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment