The Django Trial

**This is my personal note along with my studying. I am sorry that I am not really helpful if you look for some tutorials. I use my blog to memorise my techy archives.

I started to study Django more deeply since I use Python for data analysing and I may be able to build an app to visualise graphs along with those results.

I am currently having anaconda python for setups. I don’t know why I don’t have the anaconda python as default-it used to be. Hope to find a way to default it or…perhaps initialise my Mac in the future :/

Once again, to have my anaconda as default,

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

export PATH="$HOME/anaconda/bin:$PATH"

After setting python 2.7.9, I made my virtual environment.

virtualenv lwc

cd lwc

source bin/activate

pip install django==1.6.5 startproject lwc

cd lwc

python runserver

python syncdb


Stock Market analysis practice

*This is not a tutorial post but just notes of practicing on following tech materials.

I have studied the python data visualization course performed by Jose Portlla. I highly recommend this course if you are interested in Python drills. At this post, I am writing my note while I practice stock market analysis.

import pandas as pd
from pandas import Series,DataFrame
import numpy as np

import matplotlib.pyplot as plt
import seaborn as sns

from import DataReader

from datetime import datetime

from __future__ import division

I recall some libraries to generate graphs. In the tutorial operated by Jose, Yahoo data and pandas have been used to grab some data.

For more detail, probably you need to go to Udemy and see the lectures note. In this post, I am just writing what I’ve been practiced.

I want to see a historical view of the closing price.

AAPL['Adj Close'].plot(legend=True,figsize=(10,4))


And let’s see the volumes of tradings


Still I am very on to sloppy understanding “Why the graph looks like this?” Perhaps, this is the point where I need to study on financial analysis.

AAPL[['Adj Close','MA for 10 days','MA for 20 days','MA for 50 days']].plot(subplots=False,figsize=(10,4))

I’ve got this moving average graph.


I want to compare the daily percentage return of two stocks to check how correlated. I expect that comparing Google to itself will show me a quite-matched linear relationship.





Wow. two stocks are perfectly correlated with each other a linear relationship between its daily return values.

The blue one is a comparison between Google and Microsoft.

Seems like seaborn and pandas make all the data be represented on its comparison analysis. I couldn’t do this with Excel or other program.


I wonder if I can generate similar result in R. I am quite happy with python since I am subscribing some python course(but must of them are web development though.) Hopefully, I can catch some R codes later along with D3.

Titanic survivor practice

*This is not a tutorial but just my personal practice notes following tech materials.


As for all data analyzing practice, I go to kaggle to grab some data. Kaggle is awesome to find and inspire myself to figure out how to analyse data with others codes.

I am not much experienced in Python. Most of people who learn python do develop Django, but I just couldn’t have myself back-end minded. I will get there soon though.

The reason why I start learning python is that there are a log of science-subjective articles and materials. Comparing to Ruby on Rails, Django is not much attractive to me-this is personal opinion- but I can see a lot of potentials to integrate web frame work with science methods, thinking of a massive libraries on Python.

There are a couple of practice materials on Kaggle and I dive into this materials since I am currently watching the course of Jose Portllia

import pandas as pd
from pandas import Series,DataFrame

titanic_df = pd.read_csv('train.csv')


I opened the file with pandas and set up the Titanic CSV.

I though there are many of survivors but obviously not.

The code above will bring the data table but I am quite don’t get it to my head. For visualising them, I imported numpy, matplotlib, and seaborn.

Those three libraries are most used ones and I am quite happy with using them so far.

I wondered how many people survived and how we should treat youths among genders. Each of passengers is having different class as well. Think might sum up the factors of survival from sinking. In this case, I didn’t take genders from whom are younger than 16.

def male_female_child(passenger):
 age,sex = passenger
 if age < 16:
 return 'child'
 return sex

titanic_df['person'] = titanic_df[['Age','Sex']].apply(male_female_child,axis=1)


I get this graph.

Ipython(I may need to say Jupyter from now on) has a lot of functions to visualise data easily. I also installed R on the kennel of Jupyter but haven’t used it yet.

Learning new language is pain so I may be stick to Python for a while.

fig = sns.FacetGrid(titanic_df, hue="Sex",aspect=4),'Age',shade= True)

oldest = titanic_df['Age'].max()
old set the x lower limit at 0


What I grab from this code is a beautiful face grid graph.


So far, I’ve gotten a great pictures of survivors based on gender, class, age but haven’t got them sectioned by cabin parts.

deck = titanic_df['Cabin'].dropna()

levels = []

for level in deck:

cabin_df = DataFrame(levels)
cabin_df.columns = ['Cabin']

cabin_df = cabin_df[cabin_df.Cabin != 'T']




I wonder if class, gender, and ages are involving to the number of survivors.





Survival rates for the 3rd class are substantially lower but considering previous graphs, It seems that more amount of men were at 3rd class.


So far I followed the instruction of Jose’s data visualisation lecture and python’s library pretty covered what I want to see.

Later, I will practice the stock market analysis following next part of Jose’s data visualisation materials.

Python env problem

I installed Anaconda so far and switching around between python 2 and 3 depending on my practice. What I almost am interested is visualising data and turning missive figures into epitomised graphs.

I had no problem to have anaconda python as default python but it continuously am back to default mac os x python which is not set up any of package controls.

I am currently using anaconda python with this tutorial

This stack post helps to me solve the problem but what annoys me is that the default python is back to mac os x python(which is 2.7.6 not conda’s 2.7.10)


export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

export PATH="$HOME/anaconda/bin:$PATH"

Journal has been re-generated

Since my previous microblog -which is tumblr- so messed up, I mean, all my archives are gone due to missing log info disaster; My current new blog is quite empty. I have my work processing files but lost all the writings. I am not a english native speaker so it may take long time to fill this new blog out so far but I will gradually keep posting here.