Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "obsids = ['ESP_012345_6789', 'ESP_987654_3210']\n",
- "imgids = ['APF00006np', 'APF0001imm']\n",
- "data = [4.3, 9.8]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>data</th>\n",
- " <th>imgids</th>\n",
- " <th>obsids</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>0</th>\n",
- " <td>4.3</td>\n",
- " <td>APF00006np</td>\n",
- " <td>ESP_012345_6789</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>1</th>\n",
- " <td>9.8</td>\n",
- " <td>APF0001imm</td>\n",
- " <td>ESP_987654_3210</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " data imgids obsids\n",
- "0 4.3 APF00006np ESP_012345_6789\n",
- "1 9.8 APF0001imm ESP_987654_3210"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df = pd.DataFrame(dict(obsids=obsids, imgids=imgids, data=data))\n",
- "df"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df.obsids = df.obsids.astype('category')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df.imgids = df.imgids.astype('category')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df.to_hdf('testdf.hdf', 'df',format='t', data_columns=True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>data</th>\n",
- " <th>imgids</th>\n",
- " <th>obsids</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>0</th>\n",
- " <td>4.3</td>\n",
- " <td>APF00006np</td>\n",
- " <td>ESP_012345_6789</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " data imgids obsids\n",
- "0 4.3 APF00006np ESP_012345_6789"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "pd.read_hdf('testdf.hdf', 'df', where='obsids=B')"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python3 (stable)",
- "language": "python",
- "name": "stable"
- },
- "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.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement