Created
March 24, 2015 15:33
-
-
Save cdeil/55c1b80e50a187692b3d 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Overwriting /tmp/data.txt\n" | |
] | |
} | |
], | |
"source": [ | |
"%%file /tmp/data.txt\n", | |
"a | b\n", | |
"1 | 2\n", | |
"3 | 4 # this is a comment\n", | |
"# another comment\n", | |
"5 | 6" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"filename = '/tmp/data.txt'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([(1.0, 2.0), (3.0, 4.0), (5.0, 6.0)], \n", | |
" dtype=[('a', '<f8'), ('b', '<f8')])" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"np.genfromtxt(filename, names=True, delimiter='|', comments='#')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<Table masked=False length=3>\n", | |
"<table id=\"table4537259288\">\n", | |
"<thead><tr><th>a</th><th>b</th></tr></thead>\n", | |
"<thead><tr><th>int64</th><th>str672</th></tr></thead>\n", | |
"<tr><td>1</td><td>2</td></tr>\n", | |
"<tr><td>3</td><td>4 # this is a comment</td></tr>\n", | |
"<tr><td>5</td><td>6</td></tr>\n", | |
"</table>" | |
], | |
"text/plain": [ | |
"<Table masked=False length=3>\n", | |
" a b \n", | |
"int64 str672 \n", | |
"----- ---------------------\n", | |
" 1 2\n", | |
" 3 4 # this is a comment\n", | |
" 5 6" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from astropy.table import Table\n", | |
"Table.read(filename, format='ascii.csv', delimiter='|', comment='\\s*#')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment