Title: How to Setup an Anaconda Project Environment Post by: startwaves on 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 - https://www.continuum.io/downloads. 2 - Setup an Anaconda Project Environment To create a new Anaconda environment, run: Quote conda create --name cryptocurrency-analysis python=3 To activate this environment, run: For Linux Quote source activate cryptocurrency-analysis For Windows Quote activate cryptocurrency-analysis To install the required dependencies in the environment, run: Quote 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: Quote jupyter notebook This will start the iPython kernel, and open your browser to Quote http://localhost:8888/ For create a new Python notebook, making sure to use the Python Quote [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: Quote 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: Quote import plotly.offline as py import plotly.graph_objs as go import plotly.figure_factory as ff py.init_notebook_mode(connected=True) 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: Quote def get_quandl_data(quandl_id): '''Download and cache Quandl dataseries''' cache_path = '{}.pkl'.format(quandl_id).replace('/','-') try: 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") df.to_pickle(cache_path) print('Cached {} at {}'.format(quandl_id, cache_path)) return df For this example we are going to extract the Kraken exchange price data: Quote # 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: Quote btc_usd_price_kraken.head() We should see a table like this: Open High Low Close Volume (BTC) Volume (Currency) Weighted Price Date 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: https://blog.patricktriest.com/analyzing-cryptocurrencies-python/ (https://blog.patricktriest.com/analyzing-cryptocurrencies-python/) |