<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 R or Python
有冇问题?!
两者都是很好的语言,对比也有很多
来自
Step1:  透视表
~ pivot_table
<ASSISTANT_TASK:>
Python Code:
print "是也乎"
%install_ext https://raw.github.com/cjdrake/ipython-magic/master/gvmagic.py
%load_ext gvmagic
%%dot digraph G4data2chat {
        graph [label="时间帐单历史数据分析{流程图}"
        ,fontsize=14.0
        ,labeljust="l",labelloc="t",center=1
        ,ranksep=0.3,center=1,ratio=compress
        ,rankdir=BT
        ];
    node[fontsize=11.0,height=0.3
        ,shape=component 
        ];
    edge [fontsize=9.0,fontcolor="#333333"
        ,arrowsize=0.6,arrowhead=vee,arrowtail=none
        ,style="setlinewidth(0.5)"
        ];
    D4LOG [label=".log\n手工记录",shape=box3d];
    D4ATL [label="aTimeLogger2\nApp.记录",shape=box3d];
    LOAER [label="数据导入器"];
    D2CSV [label=".csv数据表",shape=box3d];
    IPYNB [label="IP[y]:notebook"];
    PANDAS [label="Pandas"];
    MATPLO [label="matplotlib"];
    
    {D4LOG D4ATL}->LOAER;
        LOAER->D2CSV [label="处理各种意外数据"];
        D2CSV->IPYNB;
    {PANDAS MATPLO}->IPYNB;
}
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%pylab inline
ls csv/aTLer_14*
ls log/zq-tilog-10*
ls data/atl2_13*
df = pd.read_csv('data/atl2_130201-130301.csv')
#df[:-1]
#df.plot(kind='area')
df['活动类别']
'''
_labels = []
for k in list(df[:-1]['活动类别']):
    print k
    if "其他" == k:
        _labels.append('Others')
    elif "总计"==k:
        _labels.append('Totle')
    else:
        _labels.append(k)
print _labels
'''
df[:-1]['Percent']
labels = _labels#list(df['活动类别'])
sizes = list(df[:-1]['持续时间'])
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
#explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
plt.pie(sizes, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.show()
df = pd.read_csv('data/pom_1108.txt')
#df.index(df['date'])
df.columns
#df.describe()
#df.plot(kind='area', stacked=False)
df.plot(kind='area', stacked=False)
Explanation: R or Python
有冇问题?!
两者都是很好的语言,对比也有很多
来自: Choosing R or Python for data analysis? An infographic
给出了完备的对比
简单的说,都是好的有用的语言,只是...
程序猿
为目标时...
更加经常面对的不是海量规范数据的分析,而是海量混乱数据的整理
比如:
案例:个人时间帐单
推荐的:
我的实践
 
当年的可视化分析: 
300+行!
移动化
MrTimer
aTimeLogger2
 
问题在原始数据的 chaos
手工时间帐单:
date,tI,tO,tC,tM,tF,tS                  Pt,Pd,Pl,Po
110701,0.00,11.5,0.00,2.50,4.00,7.50
110704,3.00,0.00,1.75,4.75,6.75,8.00
...
110726,1.50,4.25,0.00,1.00,9.75,7.50    8, 6, 1, 4
110727,4.50,2.50,0.00,4.00,5.00,7.50    8, 5, 2, 8
date 含义
,tI     输入
,tO     输出
,tC     交流
,tM     杂务
,tF     家庭
,tS     睡眠
Pt      蕃茄钟
,Pd     DONE 蕃茄钟
,Pl     LOST 任务钟
,Po     OUT  蕃茄钟
不同版本的 aTL2 数据:
# android 版本
活动类别,持续时间,开始时间,结束时间,备注
Chaos,3.7,04/01 20:54,04/02 00:35,
...
活动类别,持续时间,Percent
Life,364.5,47.5
Output,182.5,23.8
Chaos,127.0,16.5
Livin,70.3,9.2
Input,23.5,3.1
其他,0.1,0.0
总计,768.0
# iOS 6.*
"活动类别","持续时间","开始时间","结束时间","备注"
"Chaos","05:30","2014-10-01 18:56","2014-10-02 00:26",
"用餐","01:15","2014-10-01 17:40","2014-10-01 18:56",
...
"活动类别","持续时间","%"
"睡眠","220:19","29.61"
"Chaos","144:28","19.42"
...
# iOS 7+
活动类别,持续时间,开始时间,结束时间,备注
GDG,1.20,2015-04-01 23:10,2015-04-02 00:22,
GDG,1.52,2015-04-01 21:39,2015-04-01 23:10,
...
活动类别,持续时间,Percent
Livin,230.98,30.1
Livin/睡眠,214.17,27.9
Livin/电影,12.05,1.6
Livin/娱乐,0.93,0.1
...
Output/Pt0+Life/交通,0.02,0.0
Life/用餐+Output/交流,0.02,0.0
其他,0.07,0.0
总计,768.00
所以,要进行一系列数据整理先,这就是 R 难以折腾的了...
iPy notebook + Jupyter
嗯啍,当然,要我更多的小伙伴,最最常见的:
Pandas
numpy
matpotlib
...
End of explanation
df = pd.read_csv('data/_all_atlogger2.csv')
df.head()
#df.columns
df.plot(kind='area', stacked=False)
df.plot(kind='kde', stacked=False)
import pandas as pd
import matplotlib.pyplot as plt
ls data/pom_*
df = pd.read_csv('data/pom_1302.txt')
df.head()
Explanation: 透视表
~ pivot_table
End of explanation
<END_TASK>