Skip to content

Commit

Permalink
Clean notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelverissimo committed Dec 19, 2019
1 parent 8938757 commit ac247f5
Showing 1 changed file with 166 additions and 5 deletions.
171 changes: 166 additions & 5 deletions jupyter-notebooks/kmeans_clustering_v01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,178 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [
{
"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>Sinal</th>\n <th>TTbar</th>\n <th>Wbb</th>\n <th>Wbl</th>\n <th>Wcc</th>\n <th>Wcl</th>\n <th>Wll</th>\n <th>WW</th>\n <th>WZ</th>\n <th>ZZ</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>#Eventos</th>\n <td>95550</td>\n <td>775105.0</td>\n <td>48691.0</td>\n <td>8106.0</td>\n <td>68830.0</td>\n <td>937593.0</td>\n <td>2078541.0</td>\n <td>290807.0</td>\n <td>345670.0</td>\n <td>12881.0</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " Sinal TTbar Wbb Wbl Wcc Wcl Wll \\\n#Eventos 95550 775105.0 48691.0 8106.0 68830.0 937593.0 2078541.0 \n\n WW WZ ZZ \n#Eventos 290807.0 345670.0 12881.0 "
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame({'Sinal' : [95550],\n",
"'TTbar' : [775105.],\n",
"'Wbb' : [48691.],\n",
"'Wbl' : [8106.],\n",
"'Wcc' : [68830.],\n",
"'Wcl' : [937593.],\n",
"'Wll' : [2078541.],\n",
"'WW' : [290807.],\n",
"'WZ' : [345670.],\n",
"'ZZ' : [12881.],\n",
"}, index=['#Eventos'])\n",
"#df = df.T \n",
"df.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "4566224.0"
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[0,1:].sum()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": []
"source": [
"df['Total de Background'] = df.iloc[0,1:].sum()\n",
"df = df.T "
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"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>#Eventos</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Sinal</th>\n <td>95550.0</td>\n </tr>\n <tr>\n <th>TTbar</th>\n <td>775105.0</td>\n </tr>\n <tr>\n <th>Wbb</th>\n <td>48691.0</td>\n </tr>\n <tr>\n <th>Wbl</th>\n <td>8106.0</td>\n </tr>\n <tr>\n <th>Wcc</th>\n <td>68830.0</td>\n </tr>\n <tr>\n <th>Wcl</th>\n <td>937593.0</td>\n </tr>\n <tr>\n <th>Wll</th>\n <td>2078541.0</td>\n </tr>\n <tr>\n <th>WW</th>\n <td>290807.0</td>\n </tr>\n <tr>\n <th>WZ</th>\n <td>345670.0</td>\n </tr>\n <tr>\n <th>ZZ</th>\n <td>12881.0</td>\n </tr>\n <tr>\n <th>Total de Background</th>\n <td>4566224.0</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " #Eventos\nSinal 95550.0\nTTbar 775105.0\nWbb 48691.0\nWbl 8106.0\nWcc 68830.0\nWcl 937593.0\nWll 2078541.0\nWW 290807.0\nWZ 345670.0\nZZ 12881.0\nTotal de Background 4566224.0"
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "95550.0"
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc['Sinal', 'Número de Eventos']"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"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>#Eventos</th>\n <th>Signal/background</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Sinal</th>\n <td>95550.0</td>\n <td>1.000000</td>\n </tr>\n <tr>\n <th>TTbar</th>\n <td>775105.0</td>\n <td>0.123274</td>\n </tr>\n <tr>\n <th>Wbb</th>\n <td>48691.0</td>\n <td>1.962375</td>\n </tr>\n <tr>\n <th>Wbl</th>\n <td>8106.0</td>\n <td>11.787565</td>\n </tr>\n <tr>\n <th>Wcc</th>\n <td>68830.0</td>\n <td>1.388203</td>\n </tr>\n <tr>\n <th>Wcl</th>\n <td>937593.0</td>\n <td>0.101910</td>\n </tr>\n <tr>\n <th>Wll</th>\n <td>2078541.0</td>\n <td>0.045970</td>\n </tr>\n <tr>\n <th>WW</th>\n <td>290807.0</td>\n <td>0.328568</td>\n </tr>\n <tr>\n <th>WZ</th>\n <td>345670.0</td>\n <td>0.276420</td>\n </tr>\n <tr>\n <th>ZZ</th>\n <td>12881.0</td>\n <td>7.417902</td>\n </tr>\n <tr>\n <th>Total de Background</th>\n <td>4566224.0</td>\n <td>0.020925</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " #Eventos Signal/background\nSinal 95550.0 1.000000\nTTbar 775105.0 0.123274\nWbb 48691.0 1.962375\nWbl 8106.0 11.787565\nWcc 68830.0 1.388203\nWcl 937593.0 0.101910\nWll 2078541.0 0.045970\nWW 290807.0 0.328568\nWZ 345670.0 0.276420\nZZ 12881.0 7.417902\nTotal de Background 4566224.0 0.020925"
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Signal/background'] = df.loc['Sinal', '#Eventos']/df['#Eventos']\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "''",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m~/anaconda3/envs/neuralringer/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 2896\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2897\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2898\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: ''",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-32-6a3ffe97ca8c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m''\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/anaconda3/envs/neuralringer/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 2993\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2994\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2995\u001b[0;31m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2996\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2997\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/neuralringer/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 2897\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2898\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2899\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2900\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2901\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msize\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: ''"
]
}
],
"source": [
"df['']"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "\\begin{tabular}{lrr}\n\\toprule\n{} & \\#Eventos & Signal/background \\\\\n\\midrule\nSinal & 95550.0 & 1.000000 \\\\\nTTbar & 775105.0 & 0.123274 \\\\\nWbb & 48691.0 & 1.962375 \\\\\nWbl & 8106.0 & 11.787565 \\\\\nWcc & 68830.0 & 1.388203 \\\\\nWcl & 937593.0 & 0.101910 \\\\\nWll & 2078541.0 & 0.045970 \\\\\nWW & 290807.0 & 0.328568 \\\\\nWZ & 345670.0 & 0.276420 \\\\\nZZ & 12881.0 & 7.417902 \\\\\nTotal de Background & 4566224.0 & 0.020925 \\\\\n\\bottomrule\n\\end{tabular}\n\n"
}
],
"source": [
"print(df.to_latex())"
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -439,4 +600,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}

0 comments on commit ac247f5

Please sign in to comment.