欢迎使用 Colaboratory!

Colaboratory 是免费的 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并且完全在云端运行。要了解更多信息,请参阅我们的常见问题解答

重要功能

执行 TensorFlow 代码

借助 Colaboratory,您只需点击一下鼠标,即可在浏览器中执行 TensorFlow 代码。下面的示例展示了两个矩阵相加的情况。

$\begin{bmatrix}

  1. & 1. & 1. \
  2. & 1. & 1. \ \end{bmatrix} + \begin{bmatrix}
  3. & 2. & 3. \
  4. & 5. & 6. \ \end{bmatrix} = \begin{bmatrix}
  5. & 3. & 4. \
  6. & 6. & 7. \ \end{bmatrix}$

In [0]:
import tensorflow as tf

input1 = tf.ones((2, 3))
input2 = tf.reshape(tf.range(1, 7, dtype=tf.float32), (2, 3))
output = input1 + input2

with tf.Session():
  result = output.eval()
result


Out[0]:
array([[2., 3., 4.],
       [5., 6., 7.]], dtype=float32)

GitHub

您可以通过依次转到“文件”>“在 GitHub 中保存一份副本…”,保存一个 Colab 笔记本副本

只需在 colab.research.google.com/github/ 后面加上路径,即可在 GitHub 上加载任何 .ipynb。例如, 将在 GitHub 上加载此 .ipynb

可视化

Colaboratory 包含很多已被广泛使用的库(例如 matplotlib),因而能够简化数据的可视化过程。


In [0]:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = [x_i + np.random.randn(1) for x_i in x]
a, b = np.polyfit(x, y, 1)
_ = plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-')


想使用新的库?请在笔记本的顶部通过 pip install 命令安装该库。然后,您就可以在笔记本的任何其他位置使用该库。要了解导入常用库的方法,请参阅导入库示例笔记本


In [0]:
!pip install -q matplotlib-venn

from matplotlib_venn import venn2
_ = venn2(subsets = (3, 2, 1))


本地运行时支持

Colab 支持连接本地计算机上的 Jupyter 运行时。有关详情,请参阅我们的文档


In [0]:
import numpy as np

In [2]:
import tushare as ts


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-d4ae70457448> in <module>()
----> 1 import tushare as ts

ModuleNotFoundError: No module named 'tushare'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

In [3]:
!pip install tushare


Collecting tushare
  Downloading https://files.pythonhosted.org/packages/ae/a8/0c33a2b8a0084dd4d8fcc9dea6f16a2f3031530b7b6dfbeb5651a66d019b/tushare-1.2.16.tar.gz (162kB)
    100% |████████████████████████████████| 163kB 6.0MB/s 
Requirement already satisfied: pandas>=0.18.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (0.22.0)
Requirement already satisfied: requests>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (2.18.4)
Collecting lxml>=3.8.0 (from tushare)
  Downloading https://files.pythonhosted.org/packages/03/a4/9eea8035fc7c7670e5eab97f34ff2ef0ddd78a491bf96df5accedb0e63f5/lxml-4.2.5-cp36-cp36m-manylinux1_x86_64.whl (5.8MB)
    100% |████████████████████████████████| 5.8MB 6.2MB/s 
Collecting simplejson>=3.16.0 (from tushare)
  Downloading https://files.pythonhosted.org/packages/e3/24/c35fb1c1c315fc0fffe61ea00d3f88e85469004713dab488dee4f35b0aff/simplejson-3.16.0.tar.gz (81kB)
    100% |████████████████████████████████| 81kB 24.3MB/s 
Requirement already satisfied: msgpack>=0.5.6 in /usr/local/lib/python3.6/dist-packages (from tushare) (0.5.6)
Requirement already satisfied: pyzmq>=16.0.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (17.0.0)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (2018.7)
Requirement already satisfied: numpy>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (1.14.6)
Requirement already satisfied: python-dateutil>=2 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (2.5.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (3.0.4)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (2.6)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (1.22)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (2018.10.15)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2->pandas>=0.18.0->tushare) (1.11.0)
Building wheels for collected packages: tushare, simplejson
  Running setup.py bdist_wheel for tushare ... - \ done
  Stored in directory: /root/.cache/pip/wheels/5e/37/62/60a8e8d148be212aaed3032e11b616efee8103195f51a29597
  Running setup.py bdist_wheel for simplejson ... - \ | done
  Stored in directory: /root/.cache/pip/wheels/5d/1a/1e/0350bb3df3e74215cd91325344cc86c2c691f5306eb4d22c77
Successfully built tushare simplejson
Installing collected packages: lxml, simplejson, tushare
Successfully installed lxml-4.2.5 simplejson-3.16.0 tushare-1.2.16

In [0]:
import tushare as ts
import tensorflow as tf

In [5]:
!pip install tushare


Collecting tushare
  Downloading https://files.pythonhosted.org/packages/ae/a8/0c33a2b8a0084dd4d8fcc9dea6f16a2f3031530b7b6dfbeb5651a66d019b/tushare-1.2.16.tar.gz (162kB)
    100% |████████████████████████████████| 163kB 5.9MB/s 
Requirement already satisfied: pandas>=0.18.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (0.22.0)
Requirement already satisfied: requests>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (2.18.4)
Collecting lxml>=3.8.0 (from tushare)
  Downloading https://files.pythonhosted.org/packages/03/a4/9eea8035fc7c7670e5eab97f34ff2ef0ddd78a491bf96df5accedb0e63f5/lxml-4.2.5-cp36-cp36m-manylinux1_x86_64.whl (5.8MB)
    100% |████████████████████████████████| 5.8MB 4.6MB/s 
Collecting simplejson>=3.16.0 (from tushare)
  Downloading https://files.pythonhosted.org/packages/e3/24/c35fb1c1c315fc0fffe61ea00d3f88e85469004713dab488dee4f35b0aff/simplejson-3.16.0.tar.gz (81kB)
    100% |████████████████████████████████| 81kB 23.6MB/s 
Requirement already satisfied: msgpack>=0.5.6 in /usr/local/lib/python3.6/dist-packages (from tushare) (0.5.6)
Requirement already satisfied: pyzmq>=16.0.0 in /usr/local/lib/python3.6/dist-packages (from tushare) (17.0.0)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (2018.7)
Requirement already satisfied: python-dateutil>=2 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (2.5.3)
Requirement already satisfied: numpy>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.18.0->tushare) (1.14.6)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (1.22)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (2018.10.15)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (2.6)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->tushare) (3.0.4)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2->pandas>=0.18.0->tushare) (1.11.0)
Building wheels for collected packages: tushare, simplejson
  Running setup.py bdist_wheel for tushare ... - \ | done
  Stored in directory: /root/.cache/pip/wheels/5e/37/62/60a8e8d148be212aaed3032e11b616efee8103195f51a29597
  Running setup.py bdist_wheel for simplejson ... - \ | done
  Stored in directory: /root/.cache/pip/wheels/5d/1a/1e/0350bb3df3e74215cd91325344cc86c2c691f5306eb4d22c77
Successfully built tushare simplejson
Installing collected packages: lxml, simplejson, tushare
Successfully installed lxml-4.2.5 simplejson-3.16.0 tushare-1.2.16

In [1]:
import os
import sys
import pandas as pd
import re
import matplotlib.pyplot as plt
import tushare as ts
import time
import numpy as np
## hengruiyiyao:601800,,hanruiguye 300618,300601 kangtai ,luoniushang:000735, hongchuanhuizhi:002930
# example of plot web_site:https://matplotlib.org/gallery/index.html
##sz3999006,601800,300732
###: 002460
df=ts.get_k_data('300033', start='2018-06-28', ktype='5')
df2=ts.get_k_data('603180', start='2018-06-28', ktype='5')
ax1 = plt.subplot2grid((8,2),(0,0),rowspan=5,colspan=1)
ax2 = plt.subplot2grid((8,2),(5,0),rowspan=3, colspan=1)
ax3 = plt.subplot2grid((8,2),(0,1),rowspan=5, colspan=1)
ax4 = plt.subplot2grid((8,2),(5,1),rowspan=3, colspan=1)
#df =df.set_index(df.date)
#ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
#ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
#ax5 = plt.subplot2grid((3, 3), (2, 2), rowspan=1)
###################################
ax1.plot(df.index[0:30],df['close'].tail(30))
ax1.plot(df.index[0:30],df['open'].tail(30))
ax2.bar(df.index[0:15],df['volume'].tail(15))
####################
ax3.plot(df2.index[0:30],df2['close'].tail(30))
ax3.plot(df2.index[0:30],df2['open'].tail(30))
ax4.bar(df2.index[0:15],df2['volume'].tail(15))
ax1.grid(True)
#ax2.grid(True)
ax3.grid(True)
#ax4.grid(True)
#ax1.hist(log=False,color=['red','green'],label=['open','close'])
#print time.asctime()
#print int(time.time())
plt.show()


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-b94e22ab4a08> in <module>()
      4 import re
      5 import matplotlib.pyplot as plt
----> 6 import tushare as ts
      7 import time
      8 import numpy as np

ModuleNotFoundError: No module named 'tushare'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

In [0]:
Add study web site:math  https://blog.csdn.net/xianlingmao/article/details/7919597

In [0]: