Kaggle 是一个数据竞赛平台,2010 年创立,2017 年被谷歌收购。平台提供大量开放的数据集和免费的计算资源。只须要注册一个账号就能够在线编写代码,分析数据。python
数据集首页 https://www.kaggle.com/bigque...git
目前有 700 多个 Kernels。介绍中说数据持续更新,目前来看更新到 2018 年 9 月。github
比特币链上数据大小超过百 GB。在这里是经过 Google Big Query API 访问,而没有任何数据文件。因此这个数据集只能在线使用,而不能下载,但它们提供了数据抽取的代码(https://github.com/blockchain...),因此能够选择本身在本地建立这部分数据。据文档介绍,每一个帐户每个月访问数据的上限是 5 TB。google
数据一共有 4 张表:blocks、inputs、outputs、transactions。spa
代码来自这里,有改动(原代码因为库版本变化,没法执行),还略去一些次要内容。code
from google.cloud import bigquery import pandas as pd client = bigquery.Client() # Query by Allen Day, GooglCloud Developer Advocate (https://medium.com/@allenday) query = """ #standardSQL SELECT o.day, COUNT(DISTINCT(o.output_key)) AS recipients FROM ( SELECT TIMESTAMP_MILLIS((timestamp - MOD(timestamp, 86400000))) AS day, output.output_pubkey_base58 AS output_key FROM `bigquery-public-data.bitcoin_blockchain.transactions`, UNNEST(outputs) AS output ) AS o GROUP BY day ORDER BY day """ query_job = client.query(query) iterator = query_job.result(timeout=30) rows = list(iterator) # Transform the rows into a nice pandas dataframe transactions = pd.DataFrame(data=[list(x.values()) for x in rows], columns=list(rows[0].keys())) # Look at the first 10 headlines transactions.head(10)
输出:orm
transactions.tail(10)
输出:blog
import matplotlib from matplotlib import pyplot as plt %matplotlib inline plt.plot(transactions['day'], transactions['recipients'])
欢迎来个人博客: https://codeplot.top/
个人博客比特币分类ip