Bitcoin Price Analysis Using Python (Tutorial)

By crypt0z | crypto0z | 24 Mar 2020


Hello Everyone! in This tutorial we are going to analyze bitcoin price Since 2019-3-24 to 2020-3-24 using Python

Before we start, Make Sure To download these third-party libraries

  • Pandas (Essential )
  • matplotlib ( inessential )

So Let's Start!

First Thing I am going to import Pandas

why do we need Pandas ? 

Pandas is an open-source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

 

pandas-1

 

And Here I Just imported Pandas As pd so we can write it easily

and imported matplotlib

 

Now I have A CSV File that contains The data that I want to analyze.

You Can Download it From This Link

 

The Following Code is what we'll use to read a CSV file

 

pandas-2

 

You Can Print It easily by writing Print(df) 

 

Now if we looked into our CSV file column(date)

pandas-3

 

Pandas Read This Date time as String so it Cant Deal with it, so we should convert it to A date/time .

how can we do that?

we can do that easily by this Code

 

pandas-4

 

in this code, I just accessed date column by df['Date']

and I used pd.to_datetime which is an inbuilt function in pandas that converts a string to a date/time.

pandas cant convert it automatically without us telling it how our date is formatted, so what we need to do here is pass in a format string specifying how dates are formatted so in this case, our date is 2020-3-24

which is Year-Month-Day, in formating code, it will be %Y-%m-%d

You can find these Codes Here

 

Now I will set index to the date column

pandas-5

 

why did we do that? 

well it more reasonable to set our index to our date column 

so if we want to access the price of bitcoin on that particular date we can easily do that

pandas-6

 

we're almost done.

 

pandas-7

 

in this code, I accessed high column which is the highest price of bitcoin 

and resample it Monthly and now we have to tell it what we are gonna do with this resampling, well we just want the max value for each of these months, so if we print it out we can see the highest price of bitcoin every month, you can resample it daily or whatever you want, you can find this codes here

 

and now what is matplotlib ? 

Matplotlib is a 2D plotting library which can be used to generate publication quality figures.

we have imported matplotlib at the beginning

 

plot

and that's all we want!

 

Hope That Was Helpful <3

How do you rate this article?

6

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.