Created
April 2, 2014 21:55
-
-
Save wd15/9944023 to your computer and use it in GitHub Desktop.
Demo Pandas for time stepping with hdf
This file contains hidden or 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": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"N = 10\n", | |
"import pandas as pd\n", | |
"import os\n", | |
"filename = './store.h5'\n", | |
"store = pd.HDFStore(filename)\n", | |
"store.close()\n", | |
"del store" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 74 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def write_data(df, step, filename):\n", | |
" with pd.get_store(filename) as store:\n", | |
" store['step {:d}'.format(step)] = df\n", | |
"\n", | |
"for step in range(3):\n", | |
" phi = np.random.random(N)\n", | |
" df = pd.DataFrame({'phi' : phi})\n", | |
" write_data(df, step, filename)\n", | |
" \n", | |
"with pd.get_store(filename) as store:\n", | |
" print store['step 0']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" phi\n", | |
"0 0.522170\n", | |
"1 0.536279\n", | |
"2 0.050037\n", | |
"3 0.614091\n", | |
"4 0.280991\n", | |
"5 0.805066\n", | |
"6 0.573573\n", | |
"7 0.005430\n", | |
"8 0.901790\n", | |
"9 0.951810\n" | |
] | |
} | |
], | |
"prompt_number": 75 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment