Skip to content

Instantly share code, notes, and snippets.

@olivx
Forked from rg3915/FromDict.ipynb
Created December 5, 2018 21:29
Show Gist options
  • Save olivx/64d657ff67ecfcc38917f5f34cc1495b to your computer and use it in GitHub Desktop.
Save olivx/64d657ff67ecfcc38917f5f34cc1495b to your computer and use it in GitHub Desktop.
Annotations of Pandas DataFrame
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"filename = '/home/dev/fix/348670_ion_annotations.tsv'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(filename, sep='\\t')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>chrom</th>\n",
" <th>pos</th>\n",
" <th>_id</th>\n",
" <th>ref</th>\n",
" <th>alt</th>\n",
" <th>qual</th>\n",
" <th>filter</th>\n",
" <th>alt_pos_strand</th>\n",
" <th>dbsnp_bin</th>\n",
" <th>dbsnp_chrom</th>\n",
" <th>...</th>\n",
" <th>gnomad_an_popmax</th>\n",
" <th>gnomad_af_popmax</th>\n",
" <th>gnomad_dp_median</th>\n",
" <th>gnomad_dref_median</th>\n",
" <th>gnomad_gq_median</th>\n",
" <th>gnomad_ab_median</th>\n",
" <th>gnomad_as_rf</th>\n",
" <th>gnomad_as_filterstatus</th>\n",
" <th>fdvr</th>\n",
" <th>hs_only</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>5</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>11</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>11</td>\n",
" <td>23</td>\n",
" <td>6</td>\n",
" <td>25</td>\n",
" <td>5</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>9</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>10</td>\n",
" <td>23</td>\n",
" <td>5</td>\n",
" <td>24</td>\n",
" <td>5</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>9</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>10</td>\n",
" <td>23</td>\n",
" <td>5</td>\n",
" <td>24</td>\n",
" <td>5</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>9</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>4</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>12</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>11</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>5</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>11</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>6</td>\n",
" <td>11</td>\n",
" <td>3</td>\n",
" <td>12</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>11</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>4</td>\n",
" <td>11</td>\n",
" <td>2</td>\n",
" <td>12</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>11</td>\n",
" <td>4</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>13 rows × 265 columns</p>\n",
"</div>"
],
"text/plain": [
" chrom pos _id ref alt qual filter alt_pos_strand dbsnp_bin \\\n",
"0 4 0 19 1 1 0 4 1 0 \n",
"1 5 0 19 1 1 0 4 1 0 \n",
"2 5 0 18 1 1 0 4 1 0 \n",
"3 5 0 19 1 1 0 4 1 0 \n",
"4 5 0 19 1 1 0 4 1 0 \n",
"5 5 0 19 1 1 0 4 1 0 \n",
"6 5 0 19 1 1 0 4 1 0 \n",
"7 5 0 19 1 1 0 4 1 0 \n",
"8 5 0 19 1 1 0 4 1 0 \n",
"9 5 0 19 1 1 0 4 1 0 \n",
"10 5 0 19 1 1 0 4 1 0 \n",
"11 5 0 19 1 1 0 4 1 0 \n",
"12 5 0 19 1 1 0 4 1 0 \n",
"\n",
" dbsnp_chrom ... gnomad_an_popmax gnomad_af_popmax \\\n",
"0 4 ... 0 0 \n",
"1 5 ... 0 0 \n",
"2 5 ... 0 0 \n",
"3 5 ... 0 0 \n",
"4 5 ... 5 11 \n",
"5 5 ... 11 23 \n",
"6 5 ... 10 23 \n",
"7 5 ... 10 23 \n",
"8 5 ... 4 11 \n",
"9 5 ... 5 11 \n",
"10 5 ... 0 0 \n",
"11 5 ... 6 11 \n",
"12 5 ... 4 11 \n",
"\n",
" gnomad_dp_median gnomad_dref_median gnomad_gq_median gnomad_ab_median \\\n",
"0 0 0 0 0 \n",
"1 0 0 0 0 \n",
"2 0 0 0 0 \n",
"3 0 0 0 0 \n",
"4 2 11 2 11 \n",
"5 6 25 5 23 \n",
"6 5 24 5 23 \n",
"7 5 24 5 23 \n",
"8 2 12 2 11 \n",
"9 2 11 2 11 \n",
"10 0 0 0 0 \n",
"11 3 12 2 11 \n",
"12 2 12 2 11 \n",
"\n",
" gnomad_as_rf gnomad_as_filterstatus fdvr hs_only \n",
"0 0 0 0 0 \n",
"1 0 0 0 0 \n",
"2 0 0 0 0 \n",
"3 0 0 0 0 \n",
"4 11 4 0 0 \n",
"5 23 9 0 0 \n",
"6 23 9 0 0 \n",
"7 23 9 0 0 \n",
"8 11 4 0 0 \n",
"9 11 4 0 0 \n",
"10 0 0 0 0 \n",
"11 11 4 0 0 \n",
"12 11 4 0 0 \n",
"\n",
"[13 rows x 265 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Como ver o tamanho de todos os campos\n",
"df.applymap(lambda el: len(el) if isinstance(el, str) else 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment