Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 12,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import pandas as pd\n",
  10. "\n",
  11. "FemPreg_names = [\n",
  12. " \"caseid\", \"nbrnaliv\", \n",
  13. " \"babysex\", \"birthwgt_lb\",\n",
  14. " \"birthwgt_oz\", \"prglength\", \n",
  15. " \"outcome\", \"birthord\",\n",
  16. " \"agepreg\", \"finalwgt\"\n",
  17. "]\n",
  18. "\n",
  19. "FemPreg_colspecs = [\n",
  20. " (0, 12), (21, 22), \n",
  21. " (55, 56), (57, 58), \n",
  22. " (57, 59), (274, 276), \n",
  23. " (276, 277), (278, 279), \n",
  24. " (283, 285), (422, 439)\n",
  25. "]\n"
  26. ]
  27. },
  28. {
  29. "cell_type": "code",
  30. "execution_count": 15,
  31. "metadata": {
  32. "scrolled": true
  33. },
  34. "outputs": [
  35. {
  36. "data": {
  37. "text/html": [
  38. "<div>\n",
  39. "<style scoped>\n",
  40. " .dataframe tbody tr th:only-of-type {\n",
  41. " vertical-align: middle;\n",
  42. " }\n",
  43. "\n",
  44. " .dataframe tbody tr th {\n",
  45. " vertical-align: top;\n",
  46. " }\n",
  47. "\n",
  48. " .dataframe thead th {\n",
  49. " text-align: right;\n",
  50. " }\n",
  51. "</style>\n",
  52. "<table border=\"1\" class=\"dataframe\">\n",
  53. " <thead>\n",
  54. " <tr style=\"text-align: right;\">\n",
  55. " <th></th>\n",
  56. " <th>caseid</th>\n",
  57. " <th>nbrnaliv</th>\n",
  58. " <th>babysex</th>\n",
  59. " <th>birthwgt_lb</th>\n",
  60. " <th>birthwgt_oz</th>\n",
  61. " <th>prglength</th>\n",
  62. " <th>outcome</th>\n",
  63. " <th>birthord</th>\n",
  64. " <th>agepreg</th>\n",
  65. " <th>finalwgt</th>\n",
  66. " </tr>\n",
  67. " </thead>\n",
  68. " <tbody>\n",
  69. " <tr>\n",
  70. " <th>0</th>\n",
  71. " <td>1</td>\n",
  72. " <td>1.0</td>\n",
  73. " <td>1.0</td>\n",
  74. " <td>8.0</td>\n",
  75. " <td>81.0</td>\n",
  76. " <td>39</td>\n",
  77. " <td>1</td>\n",
  78. " <td>1.0</td>\n",
  79. " <td>33.0</td>\n",
  80. " <td>6448.271112</td>\n",
  81. " </tr>\n",
  82. " <tr>\n",
  83. " <th>1</th>\n",
  84. " <td>1</td>\n",
  85. " <td>1.0</td>\n",
  86. " <td>2.0</td>\n",
  87. " <td>7.0</td>\n",
  88. " <td>71.0</td>\n",
  89. " <td>39</td>\n",
  90. " <td>1</td>\n",
  91. " <td>2.0</td>\n",
  92. " <td>39.0</td>\n",
  93. " <td>6448.271112</td>\n",
  94. " </tr>\n",
  95. " <tr>\n",
  96. " <th>2</th>\n",
  97. " <td>2</td>\n",
  98. " <td>3.0</td>\n",
  99. " <td>1.0</td>\n",
  100. " <td>9.0</td>\n",
  101. " <td>9.0</td>\n",
  102. " <td>39</td>\n",
  103. " <td>1</td>\n",
  104. " <td>1.0</td>\n",
  105. " <td>14.0</td>\n",
  106. " <td>12999.542264</td>\n",
  107. " </tr>\n",
  108. " <tr>\n",
  109. " <th>3</th>\n",
  110. " <td>2</td>\n",
  111. " <td>1.0</td>\n",
  112. " <td>2.0</td>\n",
  113. " <td>7.0</td>\n",
  114. " <td>7.0</td>\n",
  115. " <td>39</td>\n",
  116. " <td>1</td>\n",
  117. " <td>2.0</td>\n",
  118. " <td>17.0</td>\n",
  119. " <td>12999.542264</td>\n",
  120. " </tr>\n",
  121. " <tr>\n",
  122. " <th>4</th>\n",
  123. " <td>2</td>\n",
  124. " <td>1.0</td>\n",
  125. " <td>2.0</td>\n",
  126. " <td>6.0</td>\n",
  127. " <td>6.0</td>\n",
  128. " <td>39</td>\n",
  129. " <td>1</td>\n",
  130. " <td>3.0</td>\n",
  131. " <td>18.0</td>\n",
  132. " <td>12999.542264</td>\n",
  133. " </tr>\n",
  134. " </tbody>\n",
  135. "</table>\n",
  136. "</div>"
  137. ],
  138. "text/plain": [
  139. " caseid nbrnaliv babysex birthwgt_lb birthwgt_oz prglength outcome \\\n",
  140. "0 1 1.0 1.0 8.0 81.0 39 1 \n",
  141. "1 1 1.0 2.0 7.0 71.0 39 1 \n",
  142. "2 2 3.0 1.0 9.0 9.0 39 1 \n",
  143. "3 2 1.0 2.0 7.0 7.0 39 1 \n",
  144. "4 2 1.0 2.0 6.0 6.0 39 1 \n",
  145. "\n",
  146. " birthord agepreg finalwgt \n",
  147. "0 1.0 33.0 6448.271112 \n",
  148. "1 2.0 39.0 6448.271112 \n",
  149. "2 1.0 14.0 12999.542264 \n",
  150. "3 2.0 17.0 12999.542264 \n",
  151. "4 3.0 18.0 12999.542264 "
  152. ]
  153. },
  154. "metadata": {},
  155. "output_type": "display_data"
  156. }
  157. ],
  158. "source": [
  159. "FemPreg_data = pd.read_fwf(\n",
  160. " '2002FemPreg.dat', \n",
  161. " names = FemPreg_names, \n",
  162. " colspecs = FemPreg_colspecs\n",
  163. ")\n",
  164. "\n",
  165. "display(FemPreg_data.head())"
  166. ]
  167. }
  168. ],
  169. "metadata": {
  170. "kernelspec": {
  171. "display_name": "Python 3",
  172. "language": "python",
  173. "name": "python3"
  174. },
  175. "language_info": {
  176. "codemirror_mode": {
  177. "name": "ipython",
  178. "version": 3
  179. },
  180. "file_extension": ".py",
  181. "mimetype": "text/x-python",
  182. "name": "python",
  183. "nbconvert_exporter": "python",
  184. "pygments_lexer": "ipython3",
  185. "version": "3.7.2"
  186. }
  187. },
  188. "nbformat": 4,
  189. "nbformat_minor": 2
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement