Tuesday, April 11, 2017

台北市住宅竊盜件數統計資料分析篇

台北市住宅竊盜件數統計資料分析篇

台北市住宅竊盜點位資訊

104年01月-106年02月

資料來源:臺北市政府警察局刑事警察大隊

資料最後更新時間:2017-03-13 19:56:55

資料連結

1. 資料擷取與匯入

In [1]:
# 首先先將資料(.csv檔)讀入
#
import pandas as pd
df = pd.read_csv("台北市10401-10602住宅竊盜點位資訊.csv", encoding='big5')
print('筆數', df.count())
df[:10]
筆數 編號      1293
案類      1293
發生日期    1293
發生時段    1293
發生地點    1293
dtype: int64
Out[1]:
編號 案類 發生日期 發生時段 發生地點
0 1 住宅竊盜 970609 01~03 台北市信義區松隆里松山路615巷1 ~ 30號
1 2 住宅竊盜 991013 22~24 台北市內湖區成功路4段331 ~ 360號
2 3 住宅竊盜 991024 13~15 台北市南港區東新里興南街52巷1 ~ 30號
3 4 住宅竊盜 1010601 07~09 台北市大安區誠安里忠孝東路3段251巷10弄1 ~ 30號
4 5 住宅竊盜 1010606 10~12 台北市中山區通北街65巷2弄1 ~ 30號
5 6 住宅竊盜 1010728 22~24 台北市萬華區萬大路486巷37弄61 ~ 90號
6 7 住宅竊盜 1020101 19~21 台北市大同區雙連里萬全街103巷
7 8 住宅竊盜 1020108 07~09 台北市中山區吉林路200巷23之1 ~ 30號
8 9 住宅竊盜 1021201 10~12 台北市大安區黎孝里和平東路3段308巷1弄1 ~ 30號
9 10 住宅竊盜 1030102 10~12 台北市文山區景美里育英街1 ~ 30號

2. 資料預處理

In [2]:
# 資料清理
# 由檔案結構可知,「案類」欄的資料都是"住宅竊盜",所以可以刪除之。
# 
del df['案類']
df[:10]
Out[2]:
編號 發生日期 發生時段 發生地點
0 1 970609 01~03 台北市信義區松隆里松山路615巷1 ~ 30號
1 2 991013 22~24 台北市內湖區成功路4段331 ~ 360號
2 3 991024 13~15 台北市南港區東新里興南街52巷1 ~ 30號
3 4 1010601 07~09 台北市大安區誠安里忠孝東路3段251巷10弄1 ~ 30號
4 5 1010606 10~12 台北市中山區通北街65巷2弄1 ~ 30號
5 6 1010728 22~24 台北市萬華區萬大路486巷37弄61 ~ 90號
6 7 1020101 19~21 台北市大同區雙連里萬全街103巷
7 8 1020108 07~09 台北市中山區吉林路200巷23之1 ~ 30號
8 9 1021201 10~12 台北市大安區黎孝里和平東路3段308巷1弄1 ~ 30號
9 10 1030102 10~12 台北市文山區景美里育英街1 ~ 30號

Friday, March 24, 2017

Edit $PATH After Anaconda Installed If 'conda' Command Can't Be Found

Edit $PATH After Anaconda Installed If 'conda' Command Can't Be Found

Anaconda is a Python package utility which contains many great packages for scientific and mathematical computation. Users just install it once and it’s all set.

Problem after installation:

The ‘conda’ command can’t be found after Anaconda installed.

Solution:

Edit the paths file in the user’s root directory according to the shell used( bash or zsh).

if using bash shell, edit .bashrcfile.
if using zsh shell, edit .zshrcfile.

Add the following line to the end of the file and save.

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

Reopen the terminal and it’s all done!

Thursday, March 23, 2017

Docker Command Note

Docker Command Note
  • Version
    $ docker --version
    Docker version 1.12.0, build 8eab29e

    $ docker-compose --version
    docker-compose version 1.8.0, build f3628c7

    $ docker-machine --version
    docker-machine version 0.8.0, build b85aac1

  • docker pull ubuntu:14.04 download latest ubuntu image

  • docker images list all images

  • docker run

    • deamon mode :
      docker run -d -p 80:80 [ubuntu(image name)] --name webserver nginx
      -d : Run container in background and print container ID
      -p : Publish a container’s port(s) to the host
      80: out/ 80: in
      –name : Assign a name to the container
      nginx : IMAGE

    • interactive mode :
      docker run -it ubuntu:14.04 | bash
      (啟動一台 ubuntu instance,並且切入bash模式)
      -i: interactive mode, 讓操作者擁有互動模式
      -t: terminal, 讓操作者可以使用終端機操作 instance

  • docker ps show containers just running
    docker ps -a show all containers (default shows just running)

  • docker start start one or more stopped containers

  • docker stop stop one or more running containers

  • docker kill kill one or more running containers

  • docker rm remove one or more containers

  • docker rmi remove one or more images

  • docker port xxxx list port mappings or a specific mapping for the running container

Ubuntu Commands

  • sudo apt-get update
  • sudo apt-get dist-upgrade

Saturday, March 4, 2017

Python And Jupyter Installation

Python And Jupyter Installation

Install Python in Mac OS X

1. Using brew is the fastest way.

python2

> brew install python

python3

> brew install python3

2. Check The Version

> python --version
Python 2.7.10
> python3 --version
Python 3.5.1

3. Check The Location of Python and Setup The Path

Mac OS X has built-in Python 2.7. By using ‘which’ command to check the location where Python installed, you can find out whether is it the system built-in python.

> which python
usr/bin/pythonsystem built-in 

In order to access to the correct version of Python installed, we need to add /usr/local/bin to $PATH.

You can use vim to edit the /etc/paths

> sudo vim /etc/paths

make sure that /usr/local/bin is before /usr/bin.

or just…

> export PATH=/usr/local/bin:$PATH

Close the terminal and reopen it again to make sure all the settings are effective.

Then check the location of Python again.

> which python 
/usr/local/bin/python
> which python3
/usr/local/bin/python3

Done!

If you always using Python 3, you can edit the setting:

> vim ~/.bash_profile

and add:

alias python="python3"

Installing Jupyter

Python2

> pip install jupyter

Python3

> pip3 install jupyter

After installation, using following command to start jupyter.

> jupyter notebook