Bitcoin Forum
October 15, 2018, 10:48:02 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: How to Setup an Anaconda Project Environment  (Read 14 times)
Offline Offline

Activity: 2
Merit: 0

View Profile
July 05, 2018, 04:57:02 AM

One of the most interesting things about Python is its power to work hand in hand with cryptocurrencies, for this reason I was inclined to learn this fabulous language and I started looking for tutorials on the net about it.

I found a great tutorial on Patrick Triest's blog that I summarized and share with you.

In this tutorial we focus on obtaining the raw data and each one will do his own analysis of the results.

To perform this basic tutorial you will need a basic understanding of Python and knowledge of the command line to set up a project.

1 - Install Anaconda

To install the dependencies for this project from scratch we are going to use Anaconda, a pre-packaged Python data science ecosystem and a dependency manager.

To setup Anaconda, I would recommend following the official installation instructions -

2 - Setup an Anaconda Project Environment

To create a new Anaconda environment, run:

conda create --name cryptocurrency-analysis python=3

To activate this environment, run:

For Linux

source activate cryptocurrency-analysis

For Windows

activate cryptocurrency-analysis

To install the required dependencies in the environment, run:

conda install numpy pandas nb_conda jupyter plotly quandl

This could take a few minutes to complete.

3 - Start An Interative Jupyter Notebook

Once the environment and dependencies are all set up, run:

jupyter notebook

This will start the iPython kernel, and open your browser to


For create a new Python notebook, making sure to use the Python

[conda env:cryptocurrency-analysis]

4 - Import the Dependencies

Once you've got a blank Jupyter notebook open, the first thing we'll do is import the required dependencies:

import os
import numpy as np
import pandas as pd
import pickle
import quandl
from datetime import datetime

We'll also import Plotly and enable the offline mode:

import plotly.offline as py
import plotly.graph_objs as go
import plotly.figure_factory as ff

With this we would have everything ready to start connecting with an API to bring data for example Bitcoin.

To test if everything is working we will start to retrieving data for analysis. First, we need to get Bitcoin pricing data using Quandl's free Bitcoin API.

For this, we will define Quandl Helper Function:

def get_quandl_data(quandl_id):
    '''Download and cache Quandl dataseries'''
    cache_path = '{}.pkl'.format(quandl_id).replace('/','-')
        f = open(cache_path, 'rb')
        df = pickle.load(f)   
        print('Loaded {} from cache'.format(quandl_id))
    except (OSError, IOError) as e:
        print('Downloading {} from Quandl'.format(quandl_id))
        df = quandl.get(quandl_id, returns="pandas")
        print('Cached {} at {}'.format(quandl_id, cache_path))
    return df

For this example we are going to extract the Kraken exchange price data:

# Pull Kraken BTC price exchange data
btc_usd_price_kraken = get_quandl_data('BCHARTS/KRAKENUSD')

We can inspect the first 5 rows of the dataframe using the head() method:


We should see a table like this:

Open           High                   Low                   Close           Volume (BTC)   Volume (Currency)   Weighted          Price
2014-01-07   874.67040   892.06753   810.00000   810.00000   15.622378           13151.472844   841.835522
2014-01-08   810.00000   899.84281   788.00000   824.98287   19.182756           16097.329584   839.156269
2014-01-09   825.56345   870.00000   807.42084   841.86934   8.158335                   6784.249982   831.572913
2014-01-10   839.99000   857.34056   817.00000   857.33056   8.024510                   6780.220188   844.938794
2014-01-11   858.20000   918.05471   857.16554   899.84105   18.748285           16698.566929   890.671709

If you want to see the original tutorial, here is the link:

Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!