Advertisement
Guest User

Untitled

a guest
Sep 17th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "## TIME data type test"
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": 1,
  13. "metadata": {
  14. "collapsed": true
  15. },
  16. "outputs": [],
  17. "source": [
  18. "from configparser import ConfigParser\n",
  19. "from os import path\n",
  20. "\n",
  21. "config = ConfigParser()\n",
  22. "config.read(path.expanduser('~/notebooks/credentials_testaccount5.ini'))\n",
  23. "\n",
  24. "user = config.get('connection', 'user')\n",
  25. "password = config.get('connection', 'password')\n",
  26. "account = config.get('connection', 'account')\n",
  27. "database=config.get('connection', 'database')\n",
  28. "schema=config.get('connection', 'schema')\n",
  29. "warehouse=config.get('connection', 'warehouse')"
  30. ]
  31. },
  32. {
  33. "cell_type": "code",
  34. "execution_count": 2,
  35. "metadata": {
  36. "collapsed": true
  37. },
  38. "outputs": [],
  39. "source": [
  40. "from sqlalchemy import create_engine\n",
  41. "from snowflake.sqlalchemy import URL\n",
  42. "engine = create_engine(URL(\n",
  43. " account=account,\n",
  44. " user=user,\n",
  45. " password=password,\n",
  46. " database=database,\n",
  47. " schema=schema,\n",
  48. " warehouse=warehouse\n",
  49. " ))"
  50. ]
  51. },
  52. {
  53. "cell_type": "code",
  54. "execution_count": 3,
  55. "metadata": {
  56. "collapsed": true
  57. },
  58. "outputs": [],
  59. "source": [
  60. "import pandas as pd\n",
  61. "from pandas import DataFrame, Series"
  62. ]
  63. },
  64. {
  65. "cell_type": "code",
  66. "execution_count": 4,
  67. "metadata": {
  68. "collapsed": false
  69. },
  70. "outputs": [
  71. {
  72. "data": {
  73. "text/html": [
  74. "<div>\n",
  75. "<table border=\"1\" class=\"dataframe\">\n",
  76. " <thead>\n",
  77. " <tr style=\"text-align: right;\">\n",
  78. " <th></th>\n",
  79. " <th>status</th>\n",
  80. " </tr>\n",
  81. " </thead>\n",
  82. " <tbody>\n",
  83. " <tr>\n",
  84. " <th>0</th>\n",
  85. " <td>Table TIME_TEST_TABLE successfully created.</td>\n",
  86. " </tr>\n",
  87. " </tbody>\n",
  88. "</table>\n",
  89. "</div>"
  90. ],
  91. "text/plain": [
  92. " status\n",
  93. "0 Table TIME_TEST_TABLE successfully created."
  94. ]
  95. },
  96. "execution_count": 4,
  97. "metadata": {},
  98. "output_type": "execute_result"
  99. }
  100. ],
  101. "source": [
  102. "pd.read_sql_query(\"\"\"\n",
  103. "create or replace table time_test_table(\n",
  104. " c1 INTEGER,\n",
  105. " c2 TIME)\n",
  106. "\"\"\",\n",
  107. " engine)"
  108. ]
  109. },
  110. {
  111. "cell_type": "code",
  112. "execution_count": 5,
  113. "metadata": {
  114. "collapsed": false
  115. },
  116. "outputs": [
  117. {
  118. "data": {
  119. "text/html": [
  120. "<div>\n",
  121. "<table border=\"1\" class=\"dataframe\">\n",
  122. " <thead>\n",
  123. " <tr style=\"text-align: right;\">\n",
  124. " <th></th>\n",
  125. " <th>number of rows inserted</th>\n",
  126. " </tr>\n",
  127. " </thead>\n",
  128. " <tbody>\n",
  129. " <tr>\n",
  130. " <th>0</th>\n",
  131. " <td>2</td>\n",
  132. " </tr>\n",
  133. " </tbody>\n",
  134. "</table>\n",
  135. "</div>"
  136. ],
  137. "text/plain": [
  138. " number of rows inserted\n",
  139. "0 2"
  140. ]
  141. },
  142. "execution_count": 5,
  143. "metadata": {},
  144. "output_type": "execute_result"
  145. }
  146. ],
  147. "source": [
  148. "pd.read_sql_query(\"\"\"\n",
  149. "insert into time_test_table\n",
  150. "values(1, '12:23:56'), (2, '23:45:07')\n",
  151. "\"\"\",\n",
  152. " engine)"
  153. ]
  154. },
  155. {
  156. "cell_type": "code",
  157. "execution_count": 6,
  158. "metadata": {
  159. "collapsed": true
  160. },
  161. "outputs": [],
  162. "source": [
  163. "df = pd.read_sql_query(\"\"\"\n",
  164. "select * from time_test_table\"\"\",\n",
  165. " engine\n",
  166. ")"
  167. ]
  168. },
  169. {
  170. "cell_type": "code",
  171. "execution_count": 7,
  172. "metadata": {
  173. "collapsed": false
  174. },
  175. "outputs": [
  176. {
  177. "data": {
  178. "text/html": [
  179. "<div>\n",
  180. "<table border=\"1\" class=\"dataframe\">\n",
  181. " <thead>\n",
  182. " <tr style=\"text-align: right;\">\n",
  183. " <th></th>\n",
  184. " <th>c1</th>\n",
  185. " <th>c2</th>\n",
  186. " </tr>\n",
  187. " </thead>\n",
  188. " <tbody>\n",
  189. " <tr>\n",
  190. " <th>0</th>\n",
  191. " <td>1</td>\n",
  192. " <td>12:23:56</td>\n",
  193. " </tr>\n",
  194. " <tr>\n",
  195. " <th>1</th>\n",
  196. " <td>2</td>\n",
  197. " <td>23:45:07</td>\n",
  198. " </tr>\n",
  199. " </tbody>\n",
  200. "</table>\n",
  201. "</div>"
  202. ],
  203. "text/plain": [
  204. " c1 c2\n",
  205. "0 1 12:23:56\n",
  206. "1 2 23:45:07"
  207. ]
  208. },
  209. "execution_count": 7,
  210. "metadata": {},
  211. "output_type": "execute_result"
  212. }
  213. ],
  214. "source": [
  215. "df"
  216. ]
  217. },
  218. {
  219. "cell_type": "code",
  220. "execution_count": null,
  221. "metadata": {
  222. "collapsed": true
  223. },
  224. "outputs": [],
  225. "source": []
  226. }
  227. ],
  228. "metadata": {
  229. "anaconda-cloud": {},
  230. "kernelspec": {
  231. "display_name": "Python [Root]",
  232. "language": "python",
  233. "name": "Python [Root]"
  234. },
  235. "language_info": {
  236. "codemirror_mode": {
  237. "name": "ipython",
  238. "version": 3
  239. },
  240. "file_extension": ".py",
  241. "mimetype": "text/x-python",
  242. "name": "python",
  243. "nbconvert_exporter": "python",
  244. "pygments_lexer": "ipython3",
  245. "version": "3.5.2"
  246. }
  247. },
  248. "nbformat": 4,
  249. "nbformat_minor": 0
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement