Advertisement
Guest User

Untitled

a guest
May 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "collapsed": false
  8. },
  9. "outputs": [],
  10. "source": [
  11. "obsids = ['ESP_012345_6789', 'ESP_987654_3210']\n",
  12. "imgids = ['APF00006np', 'APF0001imm']\n",
  13. "data = [4.3, 9.8]"
  14. ]
  15. },
  16. {
  17. "cell_type": "code",
  18. "execution_count": 2,
  19. "metadata": {
  20. "collapsed": false
  21. },
  22. "outputs": [
  23. {
  24. "data": {
  25. "text/html": [
  26. "<div>\n",
  27. "<table border=\"1\" class=\"dataframe\">\n",
  28. " <thead>\n",
  29. " <tr style=\"text-align: right;\">\n",
  30. " <th></th>\n",
  31. " <th>data</th>\n",
  32. " <th>imgids</th>\n",
  33. " <th>obsids</th>\n",
  34. " </tr>\n",
  35. " </thead>\n",
  36. " <tbody>\n",
  37. " <tr>\n",
  38. " <th>0</th>\n",
  39. " <td>4.3</td>\n",
  40. " <td>APF00006np</td>\n",
  41. " <td>ESP_012345_6789</td>\n",
  42. " </tr>\n",
  43. " <tr>\n",
  44. " <th>1</th>\n",
  45. " <td>9.8</td>\n",
  46. " <td>APF0001imm</td>\n",
  47. " <td>ESP_987654_3210</td>\n",
  48. " </tr>\n",
  49. " </tbody>\n",
  50. "</table>\n",
  51. "</div>"
  52. ],
  53. "text/plain": [
  54. " data imgids obsids\n",
  55. "0 4.3 APF00006np ESP_012345_6789\n",
  56. "1 9.8 APF0001imm ESP_987654_3210"
  57. ]
  58. },
  59. "execution_count": 2,
  60. "metadata": {},
  61. "output_type": "execute_result"
  62. }
  63. ],
  64. "source": [
  65. "df = pd.DataFrame(dict(obsids=obsids, imgids=imgids, data=data))\n",
  66. "df"
  67. ]
  68. },
  69. {
  70. "cell_type": "code",
  71. "execution_count": 3,
  72. "metadata": {
  73. "collapsed": false
  74. },
  75. "outputs": [],
  76. "source": [
  77. "df.obsids = df.obsids.astype('category')"
  78. ]
  79. },
  80. {
  81. "cell_type": "code",
  82. "execution_count": 4,
  83. "metadata": {
  84. "collapsed": true
  85. },
  86. "outputs": [],
  87. "source": [
  88. "df.imgids = df.imgids.astype('category')"
  89. ]
  90. },
  91. {
  92. "cell_type": "code",
  93. "execution_count": 5,
  94. "metadata": {
  95. "collapsed": false
  96. },
  97. "outputs": [],
  98. "source": [
  99. "df.to_hdf('testdf.hdf', 'df',format='t', data_columns=True)"
  100. ]
  101. },
  102. {
  103. "cell_type": "code",
  104. "execution_count": 6,
  105. "metadata": {
  106. "collapsed": false
  107. },
  108. "outputs": [
  109. {
  110. "data": {
  111. "text/html": [
  112. "<div>\n",
  113. "<table border=\"1\" class=\"dataframe\">\n",
  114. " <thead>\n",
  115. " <tr style=\"text-align: right;\">\n",
  116. " <th></th>\n",
  117. " <th>data</th>\n",
  118. " <th>imgids</th>\n",
  119. " <th>obsids</th>\n",
  120. " </tr>\n",
  121. " </thead>\n",
  122. " <tbody>\n",
  123. " <tr>\n",
  124. " <th>0</th>\n",
  125. " <td>4.3</td>\n",
  126. " <td>APF00006np</td>\n",
  127. " <td>ESP_012345_6789</td>\n",
  128. " </tr>\n",
  129. " </tbody>\n",
  130. "</table>\n",
  131. "</div>"
  132. ],
  133. "text/plain": [
  134. " data imgids obsids\n",
  135. "0 4.3 APF00006np ESP_012345_6789"
  136. ]
  137. },
  138. "execution_count": 6,
  139. "metadata": {},
  140. "output_type": "execute_result"
  141. }
  142. ],
  143. "source": [
  144. "pd.read_hdf('testdf.hdf', 'df', where='obsids=B')"
  145. ]
  146. }
  147. ],
  148. "metadata": {
  149. "kernelspec": {
  150. "display_name": "Python3 (stable)",
  151. "language": "python",
  152. "name": "stable"
  153. },
  154. "language_info": {
  155. "codemirror_mode": {
  156. "name": "ipython",
  157. "version": 3
  158. },
  159. "file_extension": ".py",
  160. "mimetype": "text/x-python",
  161. "name": "python",
  162. "nbconvert_exporter": "python",
  163. "pygments_lexer": "ipython3",
  164. "version": "3.5.1"
  165. }
  166. },
  167. "nbformat": 4,
  168. "nbformat_minor": 0
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement