Reader small image

You're reading from  Hands-On Bitcoin Programming with Python

Product typeBook
Published inAug 2018
Reading LevelIntermediate
Publisher
ISBN-139781789537000
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
BignumWorks Software LLP
BignumWorks Software LLP
author image
BignumWorks Software LLP

BignumWorks Software LLP is an India-based software consultancy that provides consultancy services in the area of software development and technical training. Our domain expertise includes web, mobile, cloud app development, data science projects, in-house software training services, and up-skilling services
Read more about BignumWorks Software LLP

Right arrow

Bitcoin Data Analysis

In this chapter, we will explore the manipulation and visualization of bitcoin price data using Python. We will also explore bitcoin transaction graphs, along with collecting and analyzing Bitcoin Dice game data using Python.

Manipulating and visualizing bitcoin price data

In this section, we will introduce the following topics:

  • Getting set up for data analysis
  • Getting, reading in, and cleaning bitcoin price data
  • Exploring, manipulating, and visualizing the cleaned-up data
We first need to install several Python libraries, which includes installing the pandas module for reading in data, and also doing some exploratory analysis. We'll also be installing matplotlib for creating plots and charts, as well as Jupyter Notebooks, as they are the best for this kind of work involving data analysis.

Getting set up for data analysis

To install the Python modules, open the command-line program. In the command line, to install pandas, execute the following command:

pip install pandas

Similarly, to install matplotlib, execute the following command:

pip install matplotlib

To install Jupyter, execute the following command:

pip install jupyter

Having finished installing the required modules, launch the Jupyter Notebook by executing the jupyter notebook command. This will open up a new browser window, or a tab, where it will display the list of files that are already there from the folder where we executed the jupyter notebook command. The following screenshot shows the jupyter notebook command:

Next, choose to create a new Python 3 notebook, as shown in the following screenshot:

Getting, reading in, and cleaning bitcoin price data

We will start by importing the necessary modules.

Import pandas to enable you to read in the data and start exploring it. The following screenshot shows the import pandas command:

Also, import matplotlib for drawing plots from the data.

We need to set some options for pandas and matplotlib. The following screenshot shows the command for importing matplotlib:

The first option we will set is called options.mode.chained_assignment = None.

The preceding option is to make sure that the operations are for the cleanup, which will be performed on the pandas DataFrame objects; we want the cleanup to happen on the original DataFrame objects and not on copies.

The following screenshot shows the options.mode.chained_assignment = None option:

Also, set matplotlib to visualize and display all the charts shown in the following screenshot...

Exploring, manipulating, and visualizing the cleaned-up data

As the data cleanup is done, start with the data exploration tasks. We can use the pandas date-time capabilities to run some interesting queries.

For example, if we want to get all the records from a particular year, pass that year to the DataFrame inside square brackets. The following screenshot shows the price data from the year 2010:

We can also specify whether we want the data from a particular date.

The following screenshot shows the bitcoin price in USD from August 1, 2017:

We can also specify whether we want the data from a particular period spanning certain dates.

The following screenshot shows the data from August 1, 2017, onward:

Statistical information can also be retrieved using pandas methods. For example, to get the minimum price from this dataset, we can use the min() method, as shown in the following...

Exploring bitcoin transaction graphs

In this section, we will learn about how to get the blockchain data, and provide step-by-step information as to how to explore, clean up, analyze, and visualize this data.

Bitcoin and blockchain graphs

Blockchain.info is one of the best places to look at the latest bitcoin stats and graphs. There are different kinds of charts and graphs concerning bitcoin and blockchain that are available for analysis. We can also download the data in a variety of formats—CSV, JSON, and so on. We have downloaded some of this data in CSV format in the previous section, and now we will explore this data in a Jupyter Notebook.

We start by importing the modules we need. We need pandas for data reading...

Collecting and analyzing Bitcoin Dice game data

In this section, we will look at the data from a dice games portal, read in the data from the API, and use pandas to convert it into a tabular format. We will also export the data and find the things that need cleaning up. We'll clean up, manipulate, and reshape the data, making it ready for analysis, and finally, we will draw a simple plot from the clean data.

Getting data from the Games Web API

The user can explore the dice games data from MegaDice.com, which is available from the website's API link at https://www.megadice.com.

We will use the pandas read_JSON method to read individual winner history data from the MegaDice API link. We create a pandas DataFrame,...

Summary

In this chapter, we learned how to prepare our setup for data analysis. We saw how to get, read in, and clean the price data. We also learned how to explore, manipulate, and visualize the cleaned-up data.

We also explored some of the bitcoin and blockchain graphs that we can create. We learned where to get the relevant data, and we read this data in a Jupyter Notebook and imported the necessary modules. We cleaned up and manipulated this data, and finally, we created graphs out of this data and a notebook, but without using Python.

We also explored the data from a dice games portal. We added the data from the API and used pandas to convert it into a tabular format. We explored the data and found the things that needed cleaning up. We cleaned up and manipulated the data and made it ready for analysis.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Bitcoin Programming with Python
Published in: Aug 2018Publisher: ISBN-13: 9781789537000
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
BignumWorks Software LLP

BignumWorks Software LLP is an India-based software consultancy that provides consultancy services in the area of software development and technical training. Our domain expertise includes web, mobile, cloud app development, data science projects, in-house software training services, and up-skilling services
Read more about BignumWorks Software LLP