译者:飞龙
在本书中,您将介绍比特币和区块链,以及如何参与比特币生态系统。您将了解比特币及其特性、区块链以及两者如何共同工作。您还将学习如何使用 Pi 比特币工具来用 Python 编程比特币。您将学习如何使用 Python 以编程方式与区块链 API 进行交互,以及比特币挖矿以及如何开始进行。我们还将探讨比特币交易机器人。本书还涉及探索和分析比特币生态系统中产生的大量数据;如何获取、清理、操作和可视化比特币价格数据;以及如何使用 Python 的数据分析工具分析比特币骰子游戏的数据。
In this book xff0c; you will describe bitcoin and block chains xff0c; and how to participate in bitcoin ecosystems. You will learn about bitcoins and their properties, block chains and how they work together. You will also learn how to use Pibitco tools to use Python programming bitcoins. You will learn how to use Python to interact with block API in a programmed manner xff0c; and bitcoin mining and how to start. We will also explore bitcoin trading robots. The book also involves exploring and analysing a large amount of data generated in bitco ecosystems xff1b; how to obtain, clean, operate and visualize bitco prices #xff1b; and how to use Python data analysis tools to analyse bitco.
任何有一些 Python 经验的人都可以从本书中受益,他们希望探索 Python 比特币编程并开始构建基于比特币的 Python 应用程序。
Anyone with some Python experience can benefit from this book #xff0c; they want to explore Python bitcoin programming and start building Python applications based on bitcoin.
您可以从www.packtpub.com的帐户中下载本书的示例代码文件。如果您在其他地方购买了本书,您可以访问www.packtpub.com/support并注册,以便文件直接发送到您的邮箱。
You can download an example code file for the book from www.packtpub.com. If you have purchased a book xff0c; you can visit and register xff0c; so that documents can be sent directly to your mailbox.
您可以按照以下步骤下载代码文件:
You can download code files xff1a in the following steps;
-
登录或注册www.packtpub.com。
Login or registered at www.packtpub.com.
-
选择“支持”选项卡。
Select the Support tab.
-
单击“代码下载和勘误”。
Click " Code download and survey error ".
-
在搜索框中输入书名,然后按照屏幕上的说明操作。
Enter the name & #xff0c in the search box; then operate as specified on the screen.
下载文件后,请确保使用最新版本的解压或提取文件夹:
xff0c after downloading files; please ensure that the most recent version of the folder is used to depress or extract xff1a;
-
WinRAR/7-Zip 适用于 Windows
WinAR/7-Zip for Windows
-
Zipeg/iZip/UnRarX 适用于 Mac
Zipeg/iZip/UnRarX for Mac
-
7-Zip/PeaZip 适用于 Linux
7-Zip/ PeaZip for Linux
本书的代码包也托管在 GitHub 上,网址为。如果代码有更新,将在现有的 GitHub 存储库上进行更新。
The book's code package is also hosted on GitHub & #xff0c; the address is . If the code is updated xff0c; it will be updated on the existing GitHub repository.
我们还提供了来自我们丰富书籍和视频目录的其他代码包,可在****上找到。来看看吧!
We also provided other code packages from our rich books and video catalogues xff0c; they can be found on a href="https://github.com/PacktPublishing/"**. Take a look at xff01;
我们还提供了一个 PDF 文件,其中包含本书中使用的屏幕截图/图表的彩色图片。您可以在这里下载:。
We also have a PDF file & #xff0c; it contains colour pictures of screen screenshots/ charts used in this book. You can download & #xff1a; .
本书中使用了许多文本约定。
A number of textual agreements have been used in this book.
:表示文本中的代码词、数据库表名、文件夹名、文件名、文件扩展名、路径名、虚拟 URL、用户输入和 Twitter 句柄。这是一个例子:“使用函数从这些私钥创建三个公钥。”
& #xff1a; represents code words, database tabs, folder names, filenames, file extensions, path names, virtual URLs, user input and Twitter handles in the text. This is an example & #xff1a; "Use functions to create three public keys from these private keys."
代码块设置如下:
Code blocks are set as xff1a;
任何命令行输入或输出都以以下方式编写:
Any command line input or output is prepared as xff1a;
粗体:表示新术语、重要单词或屏幕上看到的单词。例如,菜单或对话框中的单词会以这种方式出现在文本中。这是一个例子:“屏幕截图显示了统计数据(DATA | Stats)”
警告或重要提示会出现在这样的样式中。提示和技巧会出现在这样的样式中。
Warnings or important tips appear in this style. Tips and techniques appear in this style.
本章重点介绍比特币、其特点以及我们如何参与比特币生态系统。比特币生态系统由用户获取、花费和发送比特币钱包来运行。为了理解本章的概念,你应该至少对你所使用的计算机上的命令行有基本的了解,并且你的计算机上应该安装了 Python 3.x。
This chapter focuses on Bitcoin, its characteristics, and how we participate in the Bitcoin ecosystem. The Bitcoin ecosystem is operated by users who receive, spend and send bitcoin wallets. To understand the concept of this chapter xff0c; you should have at least a basic understanding of the command lines on the computer you use xff0c; and you should have Python 3.x installed on your computer.
在本章中,我们将探讨以下主题:
In this chapter xff0c; we will address the following themes xff1a;
-
介绍比特币及其特点
Introduction of bitcoin and its characteristics
-
区块链的介绍
Introduction to the block chain
-
比特币和区块链的属性
Properties of Bitcoin and Block Chains
-
如何获取比特币钱包
How to get a bitcoin wallet.
-
包括获取、发送和花费在内的不同形式的比特币钱包
Different forms of Bitcoin wallet, including acquisition, delivery and cost
在本节中,我们将探讨以下主题:
In this section xff0c; we will explore the following themes xff1a;
-
比特币
Bitcoin.
-
比特币的用途
Use of Bitcoin
-
区块链
Block Chain
-
比特币和区块链的属性
Properties of Bitcoin and Block Chains
比特币是一种数字货币。这意味着它只存在于电子记录中,与实体货币不同,你无法用手持有它。你可以使用比特币发送和接收货币(就像其他方法一样),以及用比特币支付物品和服务。比特币可以与传统货币互换。
Bitcoin is a digital currency. This means that it exists only in electronic records xff0c; unlike real currencies xff0c; you cannot hold it by hand. You can use bitcoin to send and receive currency xff08; xff09; xff0c; and pay goods and services in bitcoin. Bitcoin can be exchanged with traditional currencies.
有交易所可以购买和出售比特币。还有许多其他数字货币,但比特币是第一个也是最受欢迎的。比特币使用点对点技术运作,没有中央机构或银行管理交易,比特币的发行是由网络共同进行的。
There are exchanges where Bitcoins can be purchased and sold. There are many other digital currencies xff0c; but bitcoins are the first and most popular. Bitcoins use point-to-point technology operations xff0c; there is no central agency or bank to manage transactions xff0c; Bitcoins are issued by the network.
比特币是开源的——它的设计是公开的;没有人拥有或控制比特币,每个人都可以使用它。比特币是数字化的和去中心化的。历史上第一次,人们可以在没有中间人的情况下交换价值,这意味着对资金的更大控制和更低的费用。
Bitcoin is open source — it is designed to be open xff1b; nobody owns or controls it xff0c; everyone can use it. Bitcoin is digital and decentralized. For the first time in history xff0c; people can exchange value xff0c without intermediaries; this means greater control over money and lower costs.
它是一种加密货币,这意味着它是经过设计保护的。
It's an encrypted currency xff0c; that means it's designed to protect it.
使用比特币有很多优势。其中一些如下:
There are many advantages to the use of bitcoin. Some of them are xff1a;
-
快速和简便的支付:使用比特币进行支付非常简单和快速。你不必担心使用哪种软件。比特币网络从不休息,即使在假期也是如此。国际间的支付也非常简单;没有银行让任何人等待三个工作日,也没有额外费用,也没有最低或最高金额的特殊限制。
rapid and easy payment: payment in bitcoin is very simple and fast. You don't have to worry about the type of software you use. Bitcoin network does not rest xff0c; even during holidays. International payments are very simple xff1b; there are no banks that keep anyone waiting for three working days xff0c; there are no additional costs xff0c; and there are no special limits on the minimum or maximum amount.
-
隐私:可以使用比特币进行支付而不分享任何个人信息;不需要注册或分享任何卡信息。事实上,甚至可以在不透露身份的情况下进行支付,几乎就像使用实体货币一样。但需要注意的是,保护隐私可能需要一些努力。
Privacy: Bitcoin for payment without sharing any personal informationxff1b; no registration or sharing of any card information is required. In fact xff0c; even xff0c; almost like using a real currency. But note xff0c; privacy protection may require some effort.
-
微不足道的交易费用:使用比特币进行支付时,交易费用非常少或微不足道。接收比特币时没有费用,拥有多个钱包可以控制在花费时支付多少费用。大多数钱包都有合理的默认费用,更高的费用可以加快交易的确认。费用与转账金额无关,因此可以用相同的费用发送 10 万比特币和发送 1 比特币。
nominal transaction costs : transaction costs are very small or insignificant when paying in bitcoin. There is no fee xff0c when receiving bitcoin; multiple wallets can control how much is spent. Most wallets have reasonable default costs xff0c; higher costs can expedite the confirmation of transactions. Costs are not related to the amount transferred xff0c; hence they can be sent at the same cost of 100,000 bitcoins and 1 bitcoins. -
安全:比特币是通过电子方式创建和持有的,但没有涉及信用卡号,因此没有人可以盗取你的钱。交易使用军用级别的加密技术,非常保密。比特币将为你提供对资金的完全访问和高水平的保护,几乎可以防范所有类型的欺诈行为。
security: Bitcoin is created and held electronically xff0c; however, no credit card number xff0c is involved; therefore no one can steal your money. The transaction uses military-level encryption technology xff0c; very secret. Bitcoin will provide you with complete access to and high level of protection against money xff0c; almost all types of fraud can be prevented.
-
多重签名:比特币的多重签名功能允许企业通过只有一组人授权交易才能花费比特币来完全控制他们的支出。
Multiple signatures & #xff1a; Bitcoin's multiple signature functions allow businesses to fully control their expenditures by authorizing transactions only by a group of persons. -
对开发者来说很好:对于开发者来说,比特币是最简单的支付系统。有许多第三方支付处理服务提供 API。我们不需要在服务器上存储比特币。如果不使用任何第三方 API,可以直接将比特币节点集成到应用程序中,使其成为自己的银行和支付处理器。
is good for developers : xff0c; bitcoin is the easiest payment system for developers. There are many third-party payment processing services providing API. We do not need to store bitcoins on the server. API, is not used for any third party; bitcoin nodes can be incorporated directly into the application xff0c; they can be made into their own bank and payment processors.
简单来说,区块链是一个数字账本。它是比特币交易的公共记录,按时间顺序排列。它是一个基于比特币协议的无许可、分布式数据库,维护着不断增长的交易数据记录列表。它是分布式的,因此每个参与者都有整个区块链的副本。区块链在所有比特币用户之间共享。
Simplely xff0c; block chain is a digital book. It is a public record of bitcoin transactions xff0c; it is chronologically arranged. It is an unlicensed, distributed database based on bitcoin protocols xff0c; it maintains a growing list of transaction data records. It is distributed xff0c; thus each participant has a copy of the entire block chain. The block chain is shared among all bitcoin users.
它用于验证比特币交易的永久性,并防止双重支付。它是安全和不可变的,也经过了防篡改和修改,即使是数据存储节点的运营者也无法修改。
It is used to verify the permanent xff0c of Bitcoin transactions; and to prevent double payment. It is safe and immutable xff0c; it has also been tampered with and modified xff0c; it cannot be modified even by the operator of the data storage node.
每个区块链记录都经过密码验证,主机运行作为数据存储节点的机器。区块链由区块组成。区块是区块链中包含和确认许多等待交易的记录,如所示:
Each block chain record is authenticated with a password xff0c; the host runs the machine as a data storage node. The block chain consists of blocks. The block is a record that contains and confirms many pending transactions xff0c; for example xff1a;
。
There are other matters that require attention. For more information, see .
比特币钱包有很多不同的形式。以下是其中一些:
Bitcoin wallets have many different forms. Here are some of them xff1a;
-
有智能手机应用钱包,有在线网络钱包——例如,blockchain.info 和 coinbase.info——有基于 macOS、Linux 和 Windows 操作系统的桌面钱包,还有专用的基于硬件的钱包。
There are smartphone application wallets & #xff0c; online wallets - e. g. & #xff0c; blockchain.info and coinbase.info - there are desktop wallets based on macos, Linux and Windows operating systems & #xff0c; and dedicated hardware-based wallets.
-
在线网络钱包可以从任何网络浏览器和任何操作系统访问,因此它相当独立于平台:
Online wallets can be accessed from any web browser and any operating system; thus it is quite independent of the platform & #xff1a;
-
最受欢迎的之一是 coinbase.info,您可以在那里购买和发送比特币。
One of the most popular are coinbase.info,, where you can buy and send bitcoin.
-
还有一些其他的,比如 BitGo、BTC.com、Coin.Space、GreenAddress 等。还有移动钱包可以从智能手机上使用。它们适用于 Android 手机、Windows 手机、黑莓手机和 iOS 手机。一些最受欢迎的是 breadwallet、Coin.Space、Mycelium 等。
There are other xff0cs; e.g. Bitgo, BTC.com, Coin. Space, GreenAddress, etc. There are mobile wallets that can be used on smartphones. They apply to Android phones, Windows phones, BlackBerry phones and iOS phones. Some of the most popular are breakwallet, Coin. Space, Mycelium, etc.
-
还有一些适用于所有操作系统的台式电脑的钱包。一些流行的钱包包括比特币核心、GreenAddress 和 BitGo 等。
There are also wallets for desktop computers that apply to all operating systems. Some popular wallets include bitcoin cores, GreenAddress and BitGo.
-
比特币钱包可能需要特定的硬件解决方案,例如 Trezor。Trezor 是一个硬件钱包,具有更高的安全性,我们甚至可以签署交易,连接到在线设备,并从该钱包中花费比特币。它是一个独立的设备,因此更安全,不太容易被黑客攻击。还建议您为大量比特币使用比特币冷存储。比特币冷存储可以脱机保存,例如在纸币钱包中。为此,您可以从bitaddress.org获取比特币地址,然后将其脱机存储详细信息。
Bitcoin wallets may require specific hardware solutions xff0c; e.g. Trezor. Trezor is a hardware wallet xff0c; has a higher security xff0c; we can even sign a transaction xff0c; connect to online equipment xff0c; and spend bitcoins from this wallet. It is an independent device xff0c; therefore safer xff0c; less prone to hacking. It is also recommended that you use bitcoin cold storage for a large number of bitcoins. Bitcoin cold storage can be deactivated xff0c; for example, in a paper wallet.
比特币可以从交易网站购买。交易网站的一个例子是 Coinbase.info,而 bitcoin.org 列出了许多这样的交易网站。一些是全球运营的,而一些是特定于某个国家或地区的,具体取决于该国家的法律。世界各地都有可用的交易所。例如,最受欢迎的之一是 Coinbase.com。在这里,可以发送和出售比特币,并且可以查看您的帐户详细信息,其中包含您持有的比特币信息。
Bitcoin can be purchased from a trading site. One example of a trading site is Coinbase.info, and bitcoin.org lists many of these trading sites. Some are globally operated xff0c; others are country- or region-specific xff0c; depending on the laws of the country. There are available exchanges around the world. xff0c; one of the most popular are Coinbase.com. Here xff0c; you can send and sell bitcoinxff0c; and you can see your account details xff0c; it contains the bitcoin information you hold.
您还可以从比特币 ATM 购买比特币。找到您当地比特币 ATM 的最佳网站之一是。例如,以下屏幕截图显示了美国的地图,您可以在上面看到所有可用的比特币 ATM,您可以在那里购买比特币:
You can also buy bitcoin from Bitcoin ATM. One of the best websites you can find in your local bitcoin ATM is . For example, xff0c; the screen screenshot below shows the map of the United States xff0c; you can see all available bitcoinATMxff0c; you can buy bitcoin#xff1a;
您还可以与其他用户面对面购买比特币。有兴趣出售比特币的人的位置可以在找到。在下面的屏幕截图中,我们可以看到所有有兴趣出售比特币的美国人。其他用户可以从该网站购买比特币。您还可以向有兴趣购买比特币的其他用户出售比特币:
You can also buy bitcoins face to face with other users. The location of people interested in selling bitcoins can be found at . On screen screen screen below xff0c; we can see all Americans interested in selling bitcoins. Other users can buy bitcoins from the website. You can also sell bitcoins@xff1a to other users interested in buying bitcoins;
。从这个网站上,我们可以搜索接受比特币付款的卖家的产品。
There are a lot of places where you can buy products and services online. One site where you can find them is . From this site xff0c; we can search the product of the seller that receives the Bitcoin payment.
例如,当我们在搜索栏中搜索烤面包机时,它将显示所有愿意接受比特币付款的卖家的列表。
For example, xff0c; when we search the toaster in the search bar xff0c; it will show a list of all vendors willing to accept Bitcoin payments.
寻找接受比特币的企业的另一个地方是。该网站包含接受比特币付款的公司列表。如下列表所示,列出了许多知名公司的名称:
Another place to look for a company that receives Bitcoin is . The website contains a list of companies that receive payment from Bitcoin. xff0c; the names of many well-known companies are xff1a, as shown in the table below;
-
WordPress:允许用户创建博客
WordPress: allows users to create blogs
-
Overstock:在线零售商
overstock: online retailer
-
Subway:接受比特币
Subway #xff1a; acceptance of Bitcoin
-
Microsoft:用户可以在 Windows 商店用比特币购买内容
Microsoft/strangxff1a; user can purchase content in bitcoin at Windows store
-
Reddit:使用比特币购买高级功能
Reddit: purchasing advanced functionality in bitcoin
如果您有兴趣寻找接受比特币的本地企业,您可以在 coinmap.org 上搜索。
If you are interested in finding a local firm that accepts Bitcoin & #xff0c; you can search on coinmap.org.
在本章中,我们介绍了比特币和区块链技术,以及我们如何开始在比特币生态系统中发挥作用。我们了解了比特币及其特性,区块链,比特币和区块链如何协同工作,以及它们之间的区别。我们还探讨了如何获取比特币钱包以及如何开始使用它。
In this chapter xff0c; we present bitcoin and block chain technology xff0c; and how we started to play a role in bitcoin ecosystems. We know bitcoin and its properties xff0c; block chains xff0c; bitcoin and block chains working together xff0c; and the difference between them. We also explore how to get bitcoin wallets and how to start using them.
我们学会了如何获取和发送比特币,并了解了在线和离线获取比特币的各种途径。我们看了如何发送比特币,并了解了一些可以花费比特币购买产品和服务的地方。
We learned how to get and send bitcoin #xff0c; we learned a variety of ways to get bitcoin online and offline. We saw how to send bitcoin #xff0c; and we found some places where bitcoin could buy products and services.
在下一章中,我们将以编程方式探索比特币和区块链 API,并了解如何开始挖掘比特币。
In the next chapter, xff0c; we will explore bitcoin and block chains API, in a programmed manner; and we will know how to start digging bitcoin.
本章重点介绍使用树莓派比特币工具来使用 Python 编程比特币,并以编程方式与区块链 API 进行交互。读者还将对挖掘比特币及其初始阶段的过程有一个大致的了解。
This chapter focuses on the use of the Python Python programming bitcoin & #xff0c, and interacts with block API by programming. Readers will also have a general understanding of the process of digging bitcoin and its initial phase.
在本章中,我们将学习以下主题:
In this chapter xff0c; we will study the following themes xff1a;
-
使用 Python 编程比特币
Program Bitcoin with Python
-
创建多重签名比特币地址
Create Multi-Signature Bitcoin Address
-
使用 Python 进行区块链 API 编程
Use Python for block chain API programming
-
安装 Blockchain.info
Install Blockchain.info
-
Python 库
Python Library
-
学习挖掘比特币
Learn to dig bitcoin.
-
如何挖掘比特币
How to dig up bitcoin.
-
挖掘比特币的困难增加
The difficulty of digging bitcoin has increased.
在本节中,我们将介绍以下主题:
In this section xff0c; we will introduce the following theme xff1a;
-
树莓派比特币工具库及如何开始使用它
Berry Pittcoin and how to start using it.
-
如何生成私钥和公钥
How to Generate Private and Public Keys
-
如何从生成的私钥和公钥创建一个简单的比特币地址
How to create a simple bitcoin address from the generated private and public keys
要使用 Python 开始比特币,必须在系统中安装 Python 3.x 和名为 Pi 比特币工具的比特币 Python 库。
To start bitcoinxff0c using Python; Python 3.x and the Bitcoin Python library called Pibitcoin tools must be installed in the system.
要安装 Pi 比特币工具库,请打开命令行程序并执行以下命令:
To install the Pi Bitcoin Toolbar xff0c; please open the command line and execute the following command xff1a;
这个库最好的地方是,您不需要在计算机上安装比特币节点就可以开始使用它。
The best place for this library is xff0c; you do not need to install a bitcoin node on a computer to start using it.
此库连接到比特币网络,并从诸如 Blockchain.info 之类的地方获取数据。
This library is connected to the Bitcoin network & #xff0c; and obtains data from places such as Blockchain.info.
我们将首先用 Python 编写比特币的等价物。在脚本中,使用 Python 创建了一个新的比特币地址的演示。
We will start with a bitcoin equivalent in Python. In the script & #xff0c; a demonstration of a new bitcoin address was created using Python.
按照以下步骤运行程序:
Run the program xff1a in accordance with the following steps;
- 导入比特币库:
- 使用随机密钥函数生成私钥:
- 在屏幕上显示私钥:
使用私钥生成公钥。通过将生成的私钥传递给函数来执行此步骤,如下所示:
Private keys are used to generate public keys. This step is carried out by passing the generated private keys to a function xff0c; xff1a as shown below;
现在,使用公钥生成比特币地址。通过将生成的公钥传递给函数来实现:
& #xff0c; Generates a bitcoin address using a public key. accomplishes & #xff1a by transmitting the resulting public key to a function;
以下屏幕截图显示了生成的私钥、公钥和比特币地址:
The following screenshot shows the generated private keys, public keys and Bitcoin address xff1a;
比特币地址
Bitcoin Address
比特币地址是一次性令牌。就像人们使用电子邮件地址发送和接收电子邮件一样,您可以使用此比特币地址发送和接收比特币。但与电子邮件地址不同,人们有许多不同的比特币地址,每个交易应使用唯一的地址。
The Bitcoin address is a one-time token. As people send and receive e-mails xff0c; you can send and receive bitcoin using this bitcoin address. But unlike e-mail addresses xff0c; people have many different bitcoin addresses xff0c; the only address should be used for each transaction.
多重签名地址是与多个私钥关联的地址;因此,我们需要创建三个私钥。
Multiple signature addresses are addresses associated with multiple private keysxff1b; thusxff0c; we need to create three private keys.
按照以下步骤创建多重签名比特币地址:
Create multi-signature bitcoin address xff1a in accordance with the following steps;
- 创建三个私钥:
- 使用函数从这些私钥创建三个公钥:
- 生成公钥后,通过将这三个公钥传递给函数来创建。将生成的传递给脚本函数以创建多重签名比特币地址。
- 打印多重签名地址并执行脚本。
以下屏幕截图显示了比特币地址的输出:
The following screenshot shows the output of the Bitcoin address xff1a;
多重签名地址在组织中非常有用,因为没有单个个人被信任授权花费比特币。
以下截图显示了统计数据(DATA | Stats)。这很棒,也很有用;但是,对于基于此数据构建应用程序或进行分析的开发人员来说,以编程方式获取这些数据非常重要:
The following screenshot shows the statistics xff08; DATA Stats). This is good xff0c; it is also useful xff1b; but xff0c; xff0c for developers who build applications or conduct analyses based on this data; it is important to programme access to these data xff1a;
以下步骤显示了比特币汇率的方法:
The following steps show the Bitcoin exchange rate methodology xff1a;
- 首先从库中导入类:
- 汇率定义了一个方法,它返回字典对象中的汇率数据。调用此方法并保存结果对象。我们拥有的字典对象具有货币符号作为键:
- 通过运行这些键,可以获取有关各种汇率的数据。例如,可以通过获取最小值来获取每种货币的最新比特币汇率:
以下截图显示了各种货币及其相应的比特币汇率,即时或过去 15 分钟内:
The following screenshot shows the various currencies and their corresponding bitcoin exchange rate xff0c; instantaneous or past 15 minutes xff1a;
- 要获取比特币市场价格,请使用类,调用市场价格并将其附加到特定货币:
- 当前比特币价格以美元显示如下:
现在让我们获取有关这个区块的一些信息。例如,可以通过在创建的对象上分别使用、和属性来获取区块费用、区块大小和区块交易,如下面的代码所示:
Now let's get some information about this block. For example, xff0c; you can get block costs, block size and block transactions xff0c by using and properties on the created object separately; xff1a as shown in the code below;
以下屏幕截图显示了区块费用、区块大小和区块交易输出:
The screenshot below shows block costs, block size and block trade output xff1a;
Blockchain.info 库中还有许多可用的功能;其中一些与钱包、创建钱包等更相关。
There are also many available functions in the Blockchain.info library xff1b; some of them are more relevant to wallets, their creation, etc.
To further explore this library & #xff0c; please visit the link .
比特币挖掘的一些特点如下:
Some of the features of Bitcoin excavation are as follows xff1a;
-
比特币挖矿是将比特币交易数据添加到比特币全球公共账本的过程。每个比特币矿工都与其他矿工一起合作,通过处理专门的分析和算术问题,将未完成的交易汇总到一个区块中。
Bitcoin mining is the process of adding bitcoin trading data to the Bitcoin global public ledger. Each bitcoin miners work with other miners xff0c; by dealing with specialized analytical and arithmetic issues xff0c; and by synthesizing unfinished transactions into a block.
-
为了获得准确性并解决问题,比特币矿工获取他们处理的所有交易。
To obtain accuracy and solve problems xff0c; Bitcoin miners get all the transactions they handle.
-
除了交易费用,矿工还会收到每个他们挖掘的区块的额外奖励。任何人都可以通过运行计算机程序参与比特币挖矿。除了在传统计算机上运行外,一些公司设计了专门的比特币挖矿硬件,可以更快地处理交易并构建区块。
In addition to transaction costs xff0c; miners receive additional incentives for each of the blocks they dig. Anyone can participate in bitcoin mining by running a computer program. xff0c, apart from running on traditional computers; some companies have designed specialized bitcoin mining hardware xff0c; and they can process transactions and build blocks faster.
You can choose to dig bitcoin on the cloud at .
这些计划的过程表明,比特币挖矿的难度正在增加,随着时间的推移变得更加昂贵。
The process of these plans shows that xff0c; that bitcoin mining is becoming more difficult xff0c; and that it is becoming more expensive over time.
一些公司购买专门的硬件来挖掘比特币。其中一种硬件是来自 21.co 公司的 21 比特币计算机。因此,这种硬件预先安装了必要的软件。
Some companies purchase specialized hardware to dig for bitcoins. One of the hardware is a 21 bitco computers. xff0c; this hardware is pre-installed with the necessary software.
还有许多可用的比特币挖矿软件,可以在任何机器上运行。然而,它可能不再那么高效。例如,让我们去查看这样的软件的长列表。它们可以在各种操作系统上运行:Windows、Linux 和 macOS。有基于 UI 的比特币矿工,也有基于命令行的比特币矿工,例如 Python 中的实现 Pyminer。
There are many other available bitcoin mining software xff0c; they can run on any machine. However, xff0c; it may not be as efficient. For example, xff0c; let's go to to see the long list of such software. They can run xff1a; Windows, Linux and macos on various operating systems. There are UI-based bitcoin miners #xff0c; there are also command-based bitcoin miners #xff0c; for example, Pyminer.
由于竞争和困难的增加,挖掘比特币时必须牢记许多因素,如下列表所示:
xff0c due to increased competition and difficulties; many factors must be borne in mind when digging bitcoin xff0c; xff1a as shown in the table below;
-
由于竞争,比特币的价格日益昂贵
Because of competition & #xff0c; Bitcoin is becoming more expensive
-
全球许多超级计算机正在竞争挖掘下一个区块和比特币。
Many supercomputers around the world are competing to dig the next block and bitcoin.
-
随着比特币矿工数量的增加,开始挖掘新比特币变得更加困难和昂贵
As the number of bitcoin miners increases xff0c; starting to dig for new bitcoin becomes more difficult and expensive
例如,以下屏幕截图显示了比特币挖矿难度的增加情况;有关更多信息,请参考。这张图表显示了过去两个月的数值。这一最近的趋势反映了比特币创立时开始的难度增加:
For example, xff0c; the following screenshot shows an increase in Bitcoin's difficulty in mining xff1b; more information xff0c; refer to . This graph shows values over the past two months. This recent trend reflects the increase in difficulties that Bitcoin began when it was created xff1a;
在本章中,我们学习了如何使用 Python 开始编程比特币。我们探索了使用 Python 进行 Blockchain.info API 编程,以获取统计数据和其他比特币市场数据。
In this chapter xff0c; we learned how to use Python to start programming bitcoin. We explored the use of Python for Blockchain.info API programming xff0c; to get statistics and other bitcoin market data.
我们还学习了如何开始挖掘比特币。我们看了看挖掘比特币的各种方式,并了解到由于竞争日益激烈和难度增加,比特币挖矿可能并不适合每个人。
We have also learned how to start digging bitcoin. We have looked at ways to dig bitcoin & #xff0c; we have learned that it may not be suitable for everyone because of increasing competition and difficulty #xff0c; bitcoin digs.
在下一章中,我们将学习如何通过在网站上接受比特币、运行基于 API 的微服务,或者构建比特币交易机器人来开始以编程方式运行比特币。
In the next chapter xff0c; we will learn how to start running bitcoin in a programmed manner by accepting bitcoin on the website, running API-based microservices xff0c; or building bitcoin trading robots.
在本章中,我们将学习如何在我们的网站上开始接受比特币作为支付方式。我们还将学习如何构建基于 API 的微服务以赚取比特币,并探索比特币交易机器人。
In this chapter xff0c; we will learn how to start accepting bitcoin as a payment on our website. We will also learn how to build API-based microservices to earn bitcoinxff0c; and explore bitcoin trading robots.
在本节中,我们将学习以下主题:
In this section xff0c; we will study the following themes xff1a;
-
如何在我们的网站上启用比特币支付
How to Enable Bitcoin Payments on our website
-
介绍 BitPay,第三方比特币 API 服务
Introduction Bitpay, third-party Bitcoin API service
-
如何生成比特币支付按钮
How to Generate Bitcoin Payment Buttons
-
如何在我们的网站上添加比特币支付按钮
How to add a bitcoin payment button to our website
有很多第三方 API 可用于网站上快速启用比特币支付,其中最流行的之一是 BitPay。
There are many third-party APIs that can be used to fast-track Bitcoin payments xff0c on the website; one of the most popular of these is Bitpay.
BitPay 可用于以多种不同的方式接受付款,包括以下方式:
Bitpay can be used to receive payments in a number of different ways xff0c; including the following mode xff1a;
-
您可以使用比特币在电子商务网站上接受在线付款
You can accept online payments using bitcoin on the e-commerce website.
-
将比特币与许多不同的电子商务解决方案集成
Integrating bitcoin with many different e-commerce solutions
-
与购物车集成
Combine with the shopping car.
-
您可以显示启用比特币的支付按钮,这对于在博客或播客上接受捐赠非常有效
You can show the payment button that enabled Bitcoin & #xff0c; this is very effective for accepting donations on blogs or podcasts
按照以下步骤生成比特币支付按钮:
Generate a bitcoin payment button based on the following steps & #xff1a;
-
First xff0c; registered and entered Bitpay, address .
-
接下来,转到“支付工具|支付按钮”页面并创建支付按钮:
Next xff0c;go to the payment tool payment button page and create the payment button xff1a;
- 要将此按钮添加到网站,只需复制 HTML 代码并粘贴到所需的网页中。
按照以下步骤将支付按钮添加到您的网站页面:
Add payment buttons to your website page xff1a in accordance with the following steps;
-
在代码编辑器中打开您网站页面的源代码。
Opens the source code for your website page in the code editor.
-
粘贴我们在上一节从 BitPay 网站复制的 HTML 代码,保存文件并重新加载网页。
Paste the HTML code & #xff0c that we copied from the Bitpay website in the previous section; save files and reload pages.
-
以下截图显示了网页上的支付按钮,用户可以使用它发送付款:
The following screenshot shows the payment button on the web page xff0c; users can use it to send payments xff1a;
。
21. Co is a platform & #xff0c; hosts a virtual market & #xff0c; developers can create and sell micro-services in exchange for Bitcoin. For more information & #xff0c; see .
我们将演示如何加入这个市场并出售微服务以赚取比特币。
We will demonstrate how to join the market and sell micro-services to earn bitcoin.
为此,我们将使用 21.co 的 SDK。
For this xff0c; we'll use 21.co's SDK.
21.co SDK 目前支持 Ubuntu 和 macOS。本节将演示在 AWS 上运行 Ubuntu 的情况。
21. Co SDK currently supports Ubuntu and macos. This section shows how Ubuntu is running on AWS.
您可以按照上的说明在 AWS 上创建 AWS Ubuntu 14.x 实例。
You can create an AWS Ubuntu 14.x example on AWS as specified on .
创建 AWS 实例后,请按照 AWS 文档页面上的说明连接到它,网址为。
Creates an AWS example & #xff0c; connects to AWS document page & #xff0c; the address is .
连接到 AWS 实例后,安装 21.co SDK。您可以通过执行以下命令来完成:
After connecting to the AWS instance xff0c; install 21.co SDK. You can complete xff1a by executing the following commands;
安装 SDK 后,通过执行以下命令登录到您的 21.co 帐户:
Install SDK after xff0c; login to your 21.co account xff1a by executing the following command;
如果用户没有 21.co 登录,则必须在 21.co 网站上创建帐户。登录后,首先加入 21.co 节点到 21.co 虚拟市场。您可以通过执行以下命令来完成:
If the user does not have 21.co login & #xff0c; an account must be created on the 21.co website. After login & #xff0c; first joins the 21.co node to the 21.co virtual market. You can complete xff1a by executing the following command;
通过执行以下命令可以实现用户加入请求的状态:
The status of the user's request can be achieved by executing the following command xff1a;
接下来,通过执行以下命令测试安装:
Next xff0c; install xff1a by performing the following command tests;
上述命令将显示所有测试都已通过,并且节点已设置并加入了 21.co 市场。
The above command will show that all tests have passed xff0c; and nodes have been set and joined in the 21.co market.
为了获取比特币余额,执行以下命令:
To obtain the bitcoin balance xff0c; execute the following command xff1a;
上述代码显示了在 21.co 账户中持有的比特币余额。
The above codes show the bitco balance held in the 21.co account.
21.co 的 SDK 捆绑了一些服务。要启动所有这些服务,请执行以下命令:
21. The SDK of Co binds a number of services. To start all these services xff0c; please execute the following command xff1a;
可能会提示安装依赖项。如果是这样,您应该继续并执行。
Could be a reminder to install a dependent item. If so, xff0c; you should continue and execute it.
有时,用户可能需要注销并重新登录以进行更改。
Sometimes xff0c; users may need to write off and re-log for change.
在 21.co 市场上出售微服务,请执行以下步骤:
Sale of micro-services on the 21.co market xff0c; please implement the following steps xff1a;
- 执行以下命令:
它将显示所有可在虚拟市场上开始销售的微服务的列表。
It will show a list of all micro-services that can be sold on the virtual market.
- 要查看服务的状态,请执行以下命令:
- 完成服务后,或者如果要停止它,请运行以下命令:
- 要查看节点上发生的所有活动,请使用以下命令:
这是如何通过在 21.co 市场上出售和列出微服务来赚取比特币的演示。
This is a demonstration of how to earn bitco by selling and listing micro-services on the 21.co market.
在本节中,我们将学习以下主题:
In this section xff0c; we will study the following themes xff1a;
-
如何获取比特币的当前出价和要价
How to get the current bid and bid for bitcoin
-
如何决定是否买入或卖出比特币
How to decide whether to buy or sell bitcoin
-
触发比特币交易建议警报
Activate bitcoin trade advice alert.
实际的比特币买卖不会被涵盖,因为涉及实际货币。但是,我们将专注于根据我们设置的条件尝试买入或卖出比特币时发送电子邮件警报。
Actual bitcoin sales will not be covered by xff0c; because it involves real currency. But xff0c; we will focus on sending e-mail alerts when trying to buy or sell bitcoin under the conditions we set.
我们将使用比特币价格 API 模块来获取比特币价格。它可以在 GitHub 上找到。
We will use the Bitcoin Price API module to get bitcoin prices. It can be found on GitHub at .
为了设置比特币交易建议警报,请按照以下步骤进行:
To set the recommended Bitcoin transaction alert xff0c; please follow the following steps xff1a;
- 首先,通过导入名为的比特币价格 API 开始:
- 还要导入,我们将用它来触发比特币价格警报。在这里,我们定义了一个名为的函数。然后设置服务器用户和电子邮件详细信息:
- 使用,发送函数发送价格警报电子邮件,如下面的代码所示:
- 接下来,为比特币定义买入和卖出价格阈值。使用这些阈值来决定是否卖出或买入比特币:
- 接下来,我们从 Bitfinex 比特币交易所使用我们在脚本中导入的模块获取当前比特币价格和当前出价。我们也可以使用其他交易所,如 CoinDesk,但目前我们将使用 Bitfinex。我们将在和中获取这些价格。
-
一旦我们得到了当前的价格,我们可以将它们与之前设置的阈值价格进行比较。
Once we get the current price xff0c; we can compare them with the previously set threshold price.
-
如果买入价格低于卖出阈值,我们调用函数发送买入触发电子邮件警报:
If the purchase price is below the selling threshold xff0c; we call the function to send the purchase to trigger e-mail alert xff1a;
- 如果卖出价格高于卖出阈值,我们调用函数发送卖出触发电子邮件警报:
谷歌搜索是搜索当前出价的最简单方法。为了实现比特币的买卖,应相应地触发两者。
Google search is the easiest way to search for the current bid. To achieve the purchase and sale of bitcoin xff0c; both should be triggered accordingly.
以下是获取当前出价的步骤:
Below are the steps to obtain the current bid #xff1a;
-
首先,检查比特币价格在线。
First xff0c; check bitcoin prices online.
-
修改脚本,使买入警报首先触发。将买入阈值设置为高于当前价格。在这里,我们将买入阈值设置为,如下面的代码所示:
Modify the script & #xff0c; triggers the purchase alarm first. Set the purchase threshold to higher than the current price. Here xff0c; we set the purchase threshold to xff0c; xff1a as shown in the code below;
- 保存脚本并执行它。以下屏幕截图显示了执行的脚本:
脚本已执行,买入警报应该已经发出。在电子邮件中检查。
Script executed xff0c; purchase alarm should have been sent. Check in email.
以下屏幕截图显示,根据我们在脚本中设置的标准,我们已收到比特币警报电子邮件,建议我们购买比特币:
The screen screenshot below shows xff0c; according to the standards we set in the script xff0c; we have received the Bitcoin alert e-mail xff0c; we are advised to purchase bitcoinxff1a;
- 最初,我们应该将出售门槛设置为低于当前价格。例如,让我们将作为门槛,并再次执行脚本。以下代码显示了设置为:
现在,出售警报应该执行。再次在电子邮件中验证。
Now xff0c; sales alarms should be executed. Verify again in e-mail.
- 验证后,我们应该看到我们已收到电子邮件警报,建议我们出售比特币,因为当前的要价高于我们愿意出售的价格:
-
脚本已准备好。您现在可以将其设置为在各种操作系统上自动运行。在 Windows 上,请使用任务计划程序。
Script is ready. You can now set it to run automatically on various operating systems. On Windows & #xff0c; please use the task plan program.
-
从“操作”菜单中,选择“创建任务…”,并将其命名为“比特币交易警报”,如下面的屏幕截图所示:
From the Operation menu & #xff0c; select "Creating Tasks..." & #xff0c; and name it "bitcoin Transaction Alert" & #xff0c; xff1a as shown in the screen screenshot below;
您还可以选择直接从脚本中触发交易,使用任何比特币交易所 API,例如 coinbase.com。由于涉及实际资金,用户需要小心处理。
You can also choose to trigger a transaction from a script directly xff0c; use any bitcoin exchange API, e. g. coinbase.com. Due to actual funds xff0c; users need to be careful.
在本章中,我们探讨了如何在网站上启用比特币支付,向您介绍了 BitPay,学习了如何生成比特币支付按钮,以及如何将支付按钮添加到我们的网站上。我们还介绍了 21.co 市场和比特币的买卖服务,以及编写了一个简单的比特币交易机器人。我们学会了如何获取比特币的当前竞价和要价。我们还学会了如何决定是买入还是卖出比特币,以及如何发送电子邮件警报,建议我们是否执行该线程。
In this chapter xff0c; we have explored how to use Bitcoin to pay xff0c; we have introduced BitPay, to you; we have learned how to generate bitco payment buttons xff0c; and how to add payment buttons to our website. We have also introduced 21.co and Bitco's sales services xff0c; and we have developed a simple bitco trading robot. We have learned how to get Bitco's current bid and bid. We have also learned how to decide whether to buy or sell bitco xff0c; and how to send e-mail alerts xff0c; we have suggested whether to execute the thread.
在下一章中,我们将学习如何对比特币数据进行数据分析。
In the next chapter, xff0c; we will learn how to compare the data with the data.
在本章中,我们将使用 Python 探索比特币价格数据的操作和可视化。我们还将探索比特币交易图表,以及使用 Python 收集和分析比特币骰子游戏数据。
In this chapter xff0c; we will use Python to explore the operation and visualization of bitcoin price data. We will also explore bitcoin trade charts xff0c; and use Python to collect and analyse bitco dice game data.
在本节中,我们将介绍以下主题:
In this section xff0c; we will introduce the following theme xff1a;
-
为数据分析做好准备
Preparing for data analysis
-
获取、读取和清理比特币价格数据
Obtain, read and clean bitcoin price data
-
探索、操作和可视化清理后的数据
Explore, operate and visualize post-cleaning data
我们首先需要安装几个 Python 库,其中包括安装模块用于读取数据,以及进行一些探索性分析。我们还将安装用于创建图表和图表,以及 Jupyter 笔记本,因为它们是进行数据分析的最佳工具。
We first need to install several Python libraries & #xff0c; these include modules to read data & #xff0c; and some exploratory analysis. We will also install charts and graphs & #xff0c; and Jupyter notebooks & #xff0c; they are the best tools for data analysis.
要安装 Python 模块,请打开命令行程序。在命令行中,要安装,请执行以下命令:
To install the Python module & #xff0c; to open the command line. In the command line xff0c; to install xff0c; to execute the following command xff1a;
类似地,要安装,请执行以下命令:
Similar to xff0c; to install xff0c; please execute the following command xff1a;
要安装 Jupyter,请执行以下命令:
To install Jupyter, please execute the following command xff1a;
完成安装所需的模块后,通过执行命令启动 Jupyter Notebook。这将在新的浏览器窗口或选项卡中打开,显示已经存在于我们执行命令的文件夹中的文件列表。以下屏幕截图显示了命令:
xff0c after completion of installation of the required module; start the Jupyter Notebook by executing the command. This opens xff0c in the new browser window or tab; displays the list of files that already exist in the folder where we execute the command. The screenshot below shows the command xff1a;
接下来,选择创建一个新的 Python 3 笔记本,如下屏幕截图所示:
Next xff0c; Select to create a new Python 3 notebook xff0c; xff1a as shown in screenshot below;
还要导入以从数据中绘制图表。
Import to draw a chart from the data.
我们需要为和设置一些选项。以下屏幕截图显示了导入的命令:
We need to set some options. The screenshot below shows the imported command #xff1a;
我们将设置的第一个选项称为。
We'll call the first option set.
前面的选项是确保清理操作是在 pandas DataFrame 对象上执行的;我们希望清理操作发生在原始 DataFrame 对象上,而不是在副本上。
The first option is to ensure that the clean-up operation is performed on a pandas DataFrame object xff1b; we want the clean-up operation to take place on the original DataFrame object xff0c; not on a copy.
以下屏幕截图显示了选项:
The screenshot below shows options & #xff1a;
还要设置以可视化和显示以下屏幕截图中显示的所有图表:
Also set to visualize and display all charts & #xff1a shown in screen screenshots below;
我们的价格数据来自,如下屏幕截图所示,它可以免费下载:
Our price data are from xff0c; xff0c as shown on screen screen screen below; it can be downloaded free of charge xff1a;
为了打印底部的记录,调用方法。该方法显示最后两条记录不应该存在,因为它们不是日期或价格。在进行进一步分析之前,我们需要删除这些记录。
This method shows that the last two records should not exist xff0c; they are not dates or prices. Before further analysis xff0c; we need to delete these records.
我们可以看到收盘价有 NaN 值,这意味着它有缺失值。我们可以利用这一因素从 DataFrame 中删除这两条记录。我们在价格上调用方法,这将删除具有一个或多个列为空或缺失值的记录。
We can see that the collected price is NaN & #xff0c; this means that it has missing values. We can use this factor to delete both records from DataFrame. We call the price method & #xff0c; this removes one or more records with empty or missing values.
请记住,我们只是从 DataFrame 价格中删除它,而不是从我们读取数据的 CSV 文件中删除它。
Remember & #xff0c; we just delete it from DataFrame prices & #xff0c; not from the CSV file where we read the data.
以下截图中的代码显示了方法的实现:
The code in the screenshot below shows how the method is achieved xff1a;
此外,再次查看底部行,看看我们想要删除的记录是否已经被删除。我们可以在以下截图中看到,实际上已经被删除了:
In addition, xff0c; again check the bottom line xff0c; see if the records we want to delete have been deleted. We can see xff0c in the following screenshot; xff1a has actually been deleted;
.
我们需要做的另一个数据清理任务是将列从对象或文本格式转换为日期时间格式。我们使用 pandas 的方法来实现这一点。
Another data cleansing task we need to do is to convert columns from object or text format to date time format. We use the pandas method to do this.
在这里,我们要求方法将字段或 DataFrame 转换,并且我们还提供了格式。然后我们将字段重新分配给 DataFrame,如下截图所示:
Here's xff0c; we're asking for ways to convert fields or DataFrame xff0c; and we're also providing formatting. Then we reassign the field to DataFrame, see xff1a in the screenshot below;
我们还需要将索引设置为列,并将列删除为单独的列。这将帮助我们对日期数据运行一些有趣的查询。
We also need to set the index to column #xff0c; and delete the column as a separate column. This will help us run some interesting queries about date data.
以下截图中的代码显示了如何将索引设置为列:
The code in the following screenshot shows how the index is set to column #xff1a;
数据清理完成后,开始进行数据探索任务。我们可以使用 pandas 日期时间功能运行一些有趣的查询。
After data cleansing xff0c; data exploration tasks are started. We can run some interesting queries using the pandas date time function.
例如,如果我们想要获取特定年份的所有记录,将该年份传递给 DataFrame 内的方括号。以下截图显示了 2010 年的价格数据:
For example xff0c; if we want to get all records for a given year xff0c; pass that year to the square brackets in DataFrame. The following screenshot shows price data for 2010 xff1a;
我们还可以指定我们是否要从特定日期获取数据。
We can also specify whether we want to obtain data from a specific date.
以下截图显示了 2017 年 8 月 1 日的比特币价格:
The following screenshot shows the Bitcoin price of xff1a on 1 August 2017;
要获取最高价格,使用方法,如下图所示:
To obtain the maximum price xff0c; method of use xff0c; xff1a as shown in the figure below;
我们还可以放大到特定的时间段。例如,为了仅绘制 2017 年的数据,首先选择来自 2017 年的数据,然后在数据子集上调用方法。
We can also zoom into specific time periods. For example, xff0c; to draw data only for 2017 xff0c; first to select data from 2017 xff0c; and then to call methods on the subset of data.
在下图中,我们有 2017 年以后的价格数据的图表:
In the figure below xff0c; we have price data after 2017 xff1a;
为了探索这些数据,我们使用方法查看顶部的记录,并在 DataFrame 上调用方法以获取更多信息,例如有多少记录、有多少空记录或缺失记录,或各列的数据类型是什么。
To explore these data xff0c; we use methods to view top records xff0c; and to call on DataFrame to get more information xff0c; e.g. how many records, how many blank records or missing records xff0c; or what type of data is in each column.
我们可以看到列显示为对象。我们将其更改为日期时间以可视化这些数据。为此,我们使用方法,并将转换后的值分配回同一列——DataFrame。
We can see the columns as objects. We change them to date time to visualize the data. To this end, we use method & #xff0c; and assign the converted values back to the same column, DataFrame.
以下屏幕截图描述了比特币的日期格式:
The following screenshot depicts the date format of Bitcoin xff1a;
将 DataFrame 的索引设置为列,并删除列作为单独的列。执行此步骤以利用 pandas 的时间序列功能。
Sets the DataFrame index to column & #xff0c; and removes the column as a separate column. Executes this step to use the time series function for pandas.
现在,通过在 DataFrame 上调用和来再次检查是否发生了更改。
& #xff0c; Checks if changes have occurred again by calling and calling on DataFrame.
以下屏幕截图显示了特定日期范围内的比特币:
The screenshot below shows bitcoin #xff1a within a given date range;
现在我们准备从这些数据创建图表。在 DataFrame 上调用方法,然后调用方法显示图表。
Now we're going to create a chart from these data. Call method & #xff0c on DataFrame; then call method to display the chart.
它显示了已经在我们有记录的时间段内挖出的比特币总数。
It shows the total number of bitcoins that have been excavated within the time period we have recorded.
以下截图描述了前述数据的图表:
The following screenshot depicts the chart of the aforementioned data xff1a;
最初,我们使用和方法对这些数据进行可视化探索,如下截图所示:
Initially xff0c; we used and used methods to visualize the data xff0c; xff1a as shown in the screenshot below;
接下来,我们清理、转换和重塑数据,如下截图所示:
Next xff0c; we clean, convert and reconstruct data xff0c; xff1a as shown in the screenshot below;
最后,我们将在区块数据中可视化我们的交易,如下截图所示:
Finally xff0c; we will visualize our transactions in block data xff0c; xff1a as shown in the screenshot below;
同样,还有另一个例子,我们应该看一下关于显示挖矿难度的数据。挖矿数据的步骤如下:
Also xff0c; there's another example xff0c; we should look at the data on the difficulty of mining. The steps for mining data are as follows xff1a;
- 读取数据,如下截图所示:
- 清理数据,如下截图所示:
我们可以看到多年来挖矿难度逐渐增加,并呈上升趋势。这些只是交易图表的几个例子。比特币和区块链生态系统中还有很多其他可供您探索的数据。
These are just a few examples of trade charts. There are a lot of other data in Bitcoin and block chain ecosystems that you can explore.
在下一个模块中,我们将学习如何收集和分析比特币骰子游戏数据。
In the next module xff0c; we will learn how to collect and analyse bitcoin dice game data.
在本节中,我们将查看来自骰子游戏门户的数据,从 API 中读取数据,并使用将其转换为表格格式。我们还将导出数据并找到需要清理的内容。我们将清理、操作和重塑数据,使其准备好进行分析,最后,我们将从干净的数据中绘制一个简单的图表。
In this section xff0c; we will look at data from the dice game portal xff0c; read data from API xff0c; and use it to convert to table format. We will also export data and find what needs to be cleaned up. We will clean, operate and reshape data xff0c; prepare them for analysis xff0c; last xff0c; and we will draw a simple chart from clean data.
用户可以从 MegaDice.com 上的 API 链接探索骰子游戏数据,该数据可从网站的 API 链接获取。
Users can explore dice game data from API links on MegaDice.com & #xff0c; this data can be obtained from API links on the website .
我们将使用方法从 MegaDice API 链接中读取个人赢家历史数据。我们从这些数据创建了一个名为的,并调用方法来查看这些数据的样子。
We will use the method to read individual winner history data from the MegaDice API link. From this data we create a xff0c; and the method to look at the data.
以下截图中的代码显示了 的创建:
The code in the following screenshot shows the creation of xff1a;
我们导入的数据有 703 列,其中大部分是个别日期。我们将删除最后一列,这不是实际数据的一部分,也不应该存在。该列显示在以下截图中:
The data we import are 703 columns & #xff0c; most of them are individual dates. We will delete the last column & #xff0c; this is not part of the actual data & #xff0c; nor should it exist. This column is shown in the following screenshot & #xff1a;
由于列太多,行太少,我们希望将列变成行,其中每个状态都有一行记录。为了执行此操作,我们需要将列翻转为行,反之亦然。为此,我们需要执行以下步骤:
Because there are too many rows xff0c; too few rows xff0c; we want to turn the column into row xff0c; each of these states is recorded in a row. For this operation xff0c; we need to turn the column to row xff0c; and vice versa. For this purpose xff0c; we need to implement the following steps xff1a;
- 首先,我们重置索引,以便将当前索引作为另一列引入。当我们翻转时,此列的值将成为列名。使用方法确认,如下截图所示:
- 接下来,使用称为或转置的方法翻转 DataFrame,如下截图所示:
- 现在,在以下截图中,我们可以看到我们的行索引已成为日期,我们之前的行已成为列:
我们已经得到了想要的列和行,但还有一些其他事情需要做。我们希望日期值以日期时间格式显示,但目前它是文本格式。然而,数据框的转置已经将日期值更改为索引。我们需要首先使用方法将它们转换为列,如下面的屏幕截图所示:
We've already got the desired columns and rows #xff0c; but there are other things to do. We want date values to be displayed in date time format xff0c; but it is currently text format. xff0c; the conversion of data boxes has changed date values to indexes. We need to first use the method to convert them to column xff0c; see xff1a in screen screenshots below;
现在我们可以将这些文本数据转换为正确的日期时间格式,如下面的屏幕截图所示:
Now we can convert these text data into the correct date time format xff0c; the screen screen screen displays xff1a below;
调用“info()”方法来确认这一点。我们在适当的日期时间格式中有了新的列“日期”。日期值需要以文本格式显示在列名索引中,如下面的屏幕截图所示:
Call info() to confirm this. We have a new column, Date, in the appropriate date time format. The date value needs to be displayed in text format in the list index & #xff0c; see xff1a on screen screen below;
我们将把索引设置回适当的“日期”列,并将“日期”列作为单独的列删除,如下面的屏幕截图所示:
We will set the index back to the appropriate “date” column xff0c; and remove xff0c from the “date” column as a separate column; see xff1a in the screen screenshot below;
现在,我们已经正确地在“日期”字段上建立了数据框的索引:
xff0c; we have correctly created a data frame index xff1a on the “date” field;
现在,这些数据可以用作时间序列函数,或者可以为不同日期子集可视化多个块等。
xff0c; these data can be used as a time sequence function xff0c; or they can visualize multiple blocks for different date subsets, etc.
在本章中,我们学习了如何准备数据分析的设置。我们看到了如何获取、读取和清理价格数据。我们还学习了如何探索、操作和可视化清理后的数据。
In this chapter xff0c; we learn how to prepare data analysis settings. We see how to get, read and clean price data. We also learn how to explore, operate and visualize post-cleaning data.
我们还探索了一些比特币和区块链图表,我们可以创建。我们学习了从哪里获取相关数据,并在 Jupyter Notebook 中读取了这些数据并导入了必要的模块。我们清理和操作了这些数据,最后,我们从这些数据和笔记本中创建了图表,但没有使用 Python。
We also explored some bitcoin and block chain charts & #xff0c; we can create. We learned where to get the relevant data & #xff0c; and we read the data in Jupyter Notebook and imported the necessary modules. We cleaned and operated the data & xff0c; xff0c; we created the chart xff0c from these data and notebooks; but did not use Python.
我们还探索了来自骰子游戏门户的数据。我们添加了来自 API 的数据,并使用 pandas 将其转换为表格格式。我们探索了数据,并找到了需要清理的内容。我们清理和操作了数据,并使其准备好进行分析。
We also explored data from the dice portal. We added data from API & #xff0c; we converted them to table format using pandas. We explored data & #xff0c; we found what needed to be cleaned up. We cleaned and operated data xff0c; and we prepared them for analysis.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论