{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"***\n",
"# 数据清洗:\n",
"> # 对占中新闻进行数据清洗\n",
"***\n",
"***\n",
"\n",
"王成军\n",
"\n",
"wangchengjun@nju.edu.cn\n",
"\n",
"计算传播网 http://computational-communication.com"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:12:43.576272Z",
"start_time": "2019-06-08T08:12:43.551029Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"# 使用with open读取每一行数据\n",
"with open(\"../data/occupycentral/zz-hk-2014-10.rtf\", encoding = 'gb18030') as f:\n",
" news = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:12:53.725761Z",
"start_time": "2019-06-08T08:12:53.713233Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"16541"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 查看总共有多少行\n",
"len(news)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:13:16.879955Z",
"start_time": "2019-06-08T08:13:16.872899Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"~~~~~~~~~~~~~~~~~~~~~~~~~~ #1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"am730 | 2014-10-31 \\par\n",
"\n",
"A16| NEWS| C观点| By 施永青 \\par \n",
"\n",
"\n",
"\n",
"法治有整合社会功能 \\par\n",
"\n",
"\\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\par\\par 前文已介绍过塔尔科特·帕森斯的AGIL理论中的Adaptation(适应)与Goal Attainment(达标)的社会功能,今天续谈Integration(整合)的功能。人类社会是一个复杂系统,大系统内还有很多次系统,这些系统既独立,又牵连;既矛盾,又互适;有时互相促进,有时互相制约。正如一个人,既是社会的成员,又是公司的雇员;既是别人的儿子,又是朋辈中的「大哥」;其言行会同时受所处的不同系统所影响。\\par\\par 这些错综复杂的系统之间不可能没有冲突,为了避免社会因纠纷得不到恰当的处理而分崩离析,社会必须发展出一套整合矛盾的方式,这就需要有司法制度。\\par\\par 按帕森斯的说法,法治的基础是先要界定产权。这样才能避免因争夺资源而产生无休止的冲突。再者,交易亦需要在产权获得界定后才能进行。有交易才有市场,才能透过市场机制进行公平竞争,推动经济发展。\\par\\par 另一方面,社会亦需要为人权下定义,这样,政府才能在有认受性的情况下组成,才能有效地去处理公众事务。此外,社会还需要有一套合乎公义的会议程序,以决定如何汇聚众人的意愿。\\par\\par 有了这些基础之后,社会就可以发展出一整套司法制度,让成员知所行止,令社会的矛盾不会恶化。\\par\\par 英国人为香港留下的,可不只是一套可以依据的律例,而是一整套法治的理念与司法程序。香港的回归能进行得相对平稳,与特区政府基本上原封不动地承继了原有的司法系统有莫大的关系。\\par\\par 回归后,虽有人危言耸听,说香港的法治已死,但世人仍公认香港的法治达国际一流水准,而港人亦可以如常在香港生活与做生意,不觉有失去法治的实质威胁。直到\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 运动的出现,香港人才真正感受到失去法治的害处。\\par\\par \\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 运动挑战的可不只是个别「恶法」,而是侵犯了整个法治的根基——产权、人权与政府的执法权。\\par\\par 占领区的物业,地契上列明有Right of way,但现在占领者却不容停车场的车辆出入。这分明损害了这些物业的产权。现在政府却无法加以维护;法庭出了禁制令,\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 者却一样藐视。这样发展下去,谁敢在香港置业?\\par\\par 其实,损害产权等同损害人权,因为人权的一项重要内容,就是个人的财产应获保障。此外,人人都应有追求幸福的权利,但现在占领区生意难做,怎会不妨碍别人追求幸福?\\par\\par \\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 者把自己的行为说成是公民抗命,但公民抗命只是个人行为在道德上的解释,用来拒绝遵守某些个人不认同的法令还讲得通,但绝不可以借此损害他人的产权与人权。\\par\\par 再者,\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 者现时在争取的是宪政改革,本应获社会上绝大多数人赞同才有条件实施,不宜用占领交通要津的方式去逼其他人就范。如果祭起公民抗命的旗帜就可以欲所欲为,只会天下大乱,令法治失去协调与整合作用。 \\par\n",
"\n",
" \\par\n",
"\n",
"\n",
"\n",
"文章编号: 201410315301186 \\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"本内容之版权由相关传媒机构 / 版权持有人拥有。除非获得明确授权,否则严禁复制、改编、分发或发布本内容。版权持有人保留一切权利。 本内容经慧科的电子服务提供。\n",
"\n",
"\\page\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~ #2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"大公报 | 2014-10-31 \\par\n",
"\n",
"A08| 要闻 \\par \n",
"\n",
"\n",
"\n",
"扛工仔料加薪4.5% 建筑金融好景 \\par\n",
"\n",
"\\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\par\\par 【大公报讯】记者彩雯报道:上班族明年加薪预测调查结果陆续揭盅,香港人力资源管理学会昨日公布调查预计,明年平均加薪4.5%,高过今年的4.3%加幅,也高过雇主联会建议的4%平均加薪幅度,年尾花红金额平均相当于一至两个月薪金,预料建筑业及金融服务业雇员明年「最好景」,预测加薪幅度最高。不过, 「\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 」持续逾一个月以及沪港通押后的影响,尚未反映在今次调查结果,有待今年底的跟进调查才能确定。\\par\\par 人力资源管理学会向101间公司调查,涉及聘用雇员总数达13.7万人。当中84间公司于今年有整体加薪,两间冻薪,今年平均加薪4.3%。展望明年,80间公司打算明年一至四月将调整基本薪金,其中52间更已落实明年预算调整幅度,当中,50间公司预期会整体加薪,两间公司冻薪,没公司打算减薪,预计明年整体加薪4.5%。调整薪酬主要考虑公司业绩、个人工作表现及通胀等因素。\\par\\par 至于年底花红,设有固定花红制度的47间公司,近40%雇员符合发放固定花红的资格,平均金额为1.01个月基本薪金。设有非固定花红的71间公司中,68%雇员获发非固定花红,平均金额为1.62个月薪金,去年有超过70%雇员获发非固定花红,平均金额为1.58个月。\\par\\par 各行业当中,金融服务业雇员可望「最好景」,调查预测今年底的非固定花红金额相当于6.3个月薪金,明年可望加薪5.9%。建筑业雇员明年加薪也可望达5.9%,但预测今年底非固定花红金额只有大约1.4个月薪金。零售业今年底非固定花红金额可望达4.72个月薪金,但明年加薪幅度预测只有4.2%,低过整体4.5%的加幅。\\par\\par 学会:调查未计\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 \\par\\par 人力资源管理学会前任会长莫家麟表示,受访公司只计算今年一至九月份的薪金调整,当时未发生「\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 」行动, 「\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 」行动已踏入第二个月,影响情况陆续浮现,但未知行动何时结束,难以预计影响的深度,他亦不便揣测。他指,沪港通会对香港带来好处,但现时通车无期,可能会将好处延后,而香港未来亦受很多不明朗因素影响。\\par\\par 香港人才管理协会与浸会大学工商管理学院早前公布薪酬调查显示,过去一年香港地区的薪酬加幅为4.2%至4.5%,由于经济情况未明朗,明年加薪幅度或放缓为4%至4.5%。雇主联会近日向逾500家企业发出加薪指引,建议明年平均加薪4%,其中建筑、医疗保健行业加幅较高。 \\par\n",
"\n",
" \\par\n",
"\n",
"\n",
"\n",
"文章编号: 201410315308873 \\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"本内容之版权由相关传媒机构 / 版权持有人拥有。除非获得明确授权,否则严禁复制、改编、分发或发布本内容。版权持有人保留一切权利。 本内容经慧科的电子服务提供。\n",
"\n",
"\\page\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~ #3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"头条日报 | 2014-10-31 \\par\n",
"\n",
"P60| 港闻| 「虎」学英语| By 汤锦标 \\par \n",
"\n",
"\n",
"\n",
"「大嘴巴」英揆闯祸记 \\par\n",
"\n",
"\\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\par\\par 本栏写过苏格兰公投,结果有惊无险,大英帝国完好无缺,英国首相卡梅伦肯定饮得杯落,原来连女皇殿下亦喜上眉梢,甚至喜极而泣。\\par\\par 苏公投独立失败,女皇喜极而泣,听落几夸张,我不是女皇肚里条虫,我讲你可以不信,但如泄密者是卡梅伦,情况自然不同。\\par\\par 话说「大嘴巴」卡梅伦在一次公众场合,同来访的前纽约市长彭博(Michael Bloomberg)咬耳仔,怎料搞出个大头佛,对话被麦克风收录,卡向彭披露女皇得悉公投结果后的一刻,直情开心到喊──Microphones picked up him saying that the Queen 'purred' a noise of contentment and had even wept for joy when Cameron called her with the news.\\par\\par 就这段公投小插曲,《英文虎报》写了一篇八卦新闻,题为 Cameron sorry for letting cat out of the bag,讲到卡梅伦「不小心」泄了女皇机密,公投一事,女皇人前扮中立,人后却喊住想保留威士忌国,卡因此要向女皇道歉──the revelation was a breach of protocol which saw a red-faced Cameron apologizing to the monarch for his big mouth.\\par\\par To let the cat out of the bag (让猫走了出袋子) 是成语,不小心泄漏别人秘密的意思,一般指无恶意,属无心之失──the idiom means to reveal a secret, usually unwittingly, and suggests thoughtlessness rather than malice.\\par\\par 除卡梅伦失礼事件外,亦可举一例。有一大班人正准备为朋友举办惊喜派对(surprise party),当事人不知情正在回家途中,给巧遇的友人抛出一句──「我会准时到你的派对」──惊喜派对马上玩完。当英国工党人士知道卡犯错后,即作出批评──It's disrespectful to let the cat out of the bag. 这句话仍有多一层意思,就是指卡不应将一些内幕消息向外界披露,亦是对女皇的不尊重。\\par\\par 英语世界中,同猫咪相关的惯用语多如牛毛,简单如raining cats and dogs, fighting like cats and dogs, when the cat's away, the mice will play 等,或者复杂少少如 a catty remark (不饶人的骂人语,多指出自女人) 、put the cat among the pigeons (刻意做出事情引起骚动)、Has the cat got your tongue?(指被人追问时保持沉默)等。\\par\\par 另一英文流行语──open a can of worms,或比 let the cat out of the bag更加广泛使用。打开罐子发现满罐都是虫子,比喻做了某件事把问题更加复杂化,举一例子(\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 运动支持者可能不爱听)──当\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 三子宣布启动\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 占中\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 行动那刻钟,a can of worms has been opened,并引致一个困难并且失控的局面。\\par\\par 欲回看《虎报》相关文章,请用以下连结。http︰//goo.gl/ul3OLJ\\par\\par 汤锦标\\par\\par 《英文虎报》The Standard总编辑逢周五见报 \\par\n",
"\n",
" \\par\n",
"\n",
"\n",
"\n",
"文章编号: 201410315308918 \\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"本内容之版权由相关传媒机构 / 版权持有人拥有。除非获得明确授权,否则严禁复制、改编、分发或发布本内容。版权持有人保留一切权利。 本内容经慧科的电子服务提供。\n",
"\n",
"\\page\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~ #4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"都市日报 | 2014-10-31 \\par\n",
"\n",
"P50| 娱乐 \\par \n",
"\n",
"\n",
"\n",
"《华尔街日报》指周润发击败成龙 \\par\n",
"\n",
"\\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"# 注意:标题和版面之间存在一个空行!所以title是block的第4个元素。\n",
"for i in range(1, 80):\n",
" print(news[i]) "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-24T07:19:32.323541Z",
"start_time": "2018-04-24T07:19:32.319728Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\par\\par 前文已介绍过塔尔科特·帕森斯的AGIL理论中的Adaptation(适应)与Goal Attainment(达标)的社会功能,今天续谈Integration(整合)的功能。人类社会是一个复杂系统,大系统内还有很多次系统,这些系统既独立,又牵连;既矛盾,又互适;有时互相促进,有时互相制约。正如一个人,既是社会的成员,又是公司的雇员;既是别人的儿子,又是朋辈中的「大哥」;其言行会同时受所处的不同系统所影响。\\par\\par 这些错综复杂的系统之间不可能没有冲突,为了避免社会因纠纷得不到恰当的处理而分崩离析,社会必须发展出一套整合矛盾的方式,这就需要有司法制度。\\par\\par 按帕森斯的说法,法治的基础是先要界定产权。这样才能避免因争夺资源而产生无休止的冲突。再者,交易亦需要在产权获得界定后才能进行。有交易才有市场,才能透过市场机制进行公平竞争,推动经济发展。\\par\\par 另一方面,社会亦需要为人权下定义,这样,政府才能在有认受性的情况下组成,才能有效地去处理公众事务。此外,社会还需要有一套合乎公义的会议程序,以决定如何汇聚众人的意愿。\\par\\par 有了这些基础之\n"
]
}
],
"source": [
"# 需要对中文编码的对象使用中文的方式进行解码\n",
"print(news[17][:500])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:18:11.309932Z",
"start_time": "2019-06-08T08:18:11.303926Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"# 定义一个函数:实现解码、编码、清洗效果\n",
"def stringclean(s):\n",
" #s = s.decode('gb18030').encode('utf8')\n",
" s = s.replace(r'\\loch\\af0\\hich\\af0\\dbch\\f15 \\b\\cf6 ', '')\n",
" s = s.replace(r'\\loch\\af0\\hich\\af0\\dbch\\f15 \\b0\\cf0 ', '')\n",
" s = s.replace('\\par', '').replace('\\n', '')\n",
" return s"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:18:19.145044Z",
"start_time": "2019-06-08T08:18:19.140561Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'bbccaadd ee '"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'aabbccaadd ee aa'.strip('a') "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:18:23.433309Z",
"start_time": "2019-06-08T08:18:23.429093Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'ccdd ee'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'aabbccdd ee'.strip('ab')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:18:25.528989Z",
"start_time": "2019-06-08T08:18:25.524345Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'abccdd ee'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'aabbccdd ee'.replace('ab', '')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:18:29.459038Z",
"start_time": "2019-06-08T08:18:29.453655Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"' 前文已介绍过塔尔科特·帕森斯的AGIL理论中的Adaptation(适应)与Goal Attainment(达标)的社会功能,今天续谈Integration(整合)的功能。人类社会是一个复杂系统,大系统内还有很多次系统,这些系统既独立,又牵连;既矛盾,又互适;有时互相促进,有时互相制约。正如一个人,既是社会的成员,又是公司的雇员;既是别人的儿子,又是朋辈中的「大哥」;其言行会同时受所处的不同系统所影响。 这些错综复杂的系统之间不可能没有冲突,为了避免社会因纠纷得不到恰当的处理而分崩离析,社会必须发展出一套整合矛盾的方式,这就需要有司法制度。 按帕森斯的说法,法治的基础是先要界定产权。这样才能避免因争夺资源而产生无休止的冲突。再者,交易亦需要在产权获得界定后才能进行。有交易才有市场,才能透过市场机制进行公平竞争,推动经济发展。 另一方面,社会亦需要为人权下定义,这样,政府才能在有认受性的情况下组成,才能有效地去处理公众事务。此外,社会还需要有一套合乎公义的会议程序,以决定如何汇聚众人的意愿。 有了这些基础之后,社会就可以发展出一整套司法制度,让成员知所行止,令社会的矛盾不会恶化。 英国人为香港留下的,可不只是一套可以依据的律例,而是一整套法治的理念与司法程序。香港的回归能进行得相对平稳,与特区政府基本上原封不动地承继了原有的司法系统有莫大的关系。 回归后,虽有人危言耸听,说香港的法治已死,但世人仍公认香港的法治达国际一流水准,而港人亦可以如常在香港生活与做生意,不觉有失去法治的实质威胁。直到占中运动的出现,香港人才真正感受到失去法治的害处。 占中运动挑战的可不只是个别「恶法」,而是侵犯了整个法治的根基——产权、人权与政府的执法权。 占领区的物业,地契上列明有Right of way,但现在占领者却不容停车场的车辆出入。这分明损害了这些物业的产权。现在政府却无法加以维护;法庭出了禁制令,占中者却一样藐视。这样发展下去,谁敢在香港置业? 其实,损害产权等同损害人权,因为人权的一项重要内容,就是个人的财产应获保障。此外,人人都应有追求幸福的权利,但现在占领区生意难做,怎会不妨碍别人追求幸福? 占中者把自己的行为说成是公民抗命,但公民抗命只是个人行为在道德上的解释,用来拒绝遵守某些个人不认同的法令还讲得通,但绝不可以借此损害他人的产权与人权。 再者,占中者现时在争取的是宪政改革,本应获社会上绝大多数人赞同才有条件实施,不宜用占领交通要津的方式去逼其他人就范。如果祭起公民抗命的旗帜就可以欲所欲为,只会天下大乱,令法治失去协调与整合作用。 '"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 调用stringclean函数\n",
"stringclean(news[17]) "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:19:00.136383Z",
"start_time": "2019-06-08T08:19:00.102287Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"16541"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 列表内的for循环\n",
"news_clean = [stringclean(n) for n in news]\n",
"len(news_clean)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:19:08.932273Z",
"start_time": "2019-06-08T08:19:08.927548Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"' 前文已介绍过塔尔科特·帕森斯的AGIL理论中的Adaptation(适应)与Goal Attainment(达标)的社会功能,今天续谈Integration(整合)的功能。人类社会是一个复杂系统,大系统内还有很多次系统,这些系统既独立,又'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"news_clean[17][:120]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:19:17.022551Z",
"start_time": "2019-06-08T08:19:17.015320Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"# 定义两个函数\n",
"def deletetab(s):\n",
" return s.replace('\\t', '')\n",
"\n",
"import sys\n",
"def flushPrint(s):\n",
" sys.stdout.write('\\r')\n",
" sys.stdout.write('%s' % s)\n",
" sys.stdout.flush() # 清洗掉 "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T01:28:47.013097Z",
"start_time": "2018-04-29T01:28:47.002696Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on OutStream in module ipykernel.iostream object:\n",
"\n",
"class OutStream(io.TextIOBase)\n",
" | A file like object that publishes the stream to a 0MQ PUB socket.\n",
" | \n",
" | Output is handed off to an IO Thread\n",
" | \n",
" | Method resolution order:\n",
" | OutStream\n",
" | io.TextIOBase\n",
" | _io._TextIOBase\n",
" | io.IOBase\n",
" | _io._IOBase\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __init__(self, session, pub_thread, name, pipe=None)\n",
" | Initialize self. See help(type(self)) for accurate signature.\n",
" | \n",
" | close(self)\n",
" | Flush and close the IO object.\n",
" | \n",
" | This method has no effect if the file is already closed.\n",
" | \n",
" | flush(self)\n",
" | trigger actual zmq send\n",
" | \n",
" | send will happen in the background thread\n",
" | \n",
" | set_parent(self, parent)\n",
" | \n",
" | write(self, string)\n",
" | Write string to stream.\n",
" | Returns the number of characters written (which is always equal to\n",
" | the length of the string).\n",
" | \n",
" | writelines(self, sequence)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n",
" | \n",
" | closed\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n",
" | \n",
" | __abstractmethods__ = frozenset()\n",
" | \n",
" | encoding = 'UTF-8'\n",
" | \n",
" | flush_interval = 0.2\n",
" | \n",
" | flush_timeout = 10\n",
" | \n",
" | topic = None\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from _io._TextIOBase:\n",
" | \n",
" | detach(...)\n",
" | Separate the underlying buffer from the TextIOBase and return it.\n",
" | \n",
" | After the underlying buffer has been detached, the TextIO is in an\n",
" | unusable state.\n",
" | \n",
" | read(...)\n",
" | Read at most n characters from stream.\n",
" | \n",
" | Read from underlying buffer until we have n characters or we hit EOF.\n",
" | If n is negative or omitted, read until EOF.\n",
" | \n",
" | readline(...)\n",
" | Read until newline or EOF.\n",
" | \n",
" | Returns an empty string if EOF is hit immediately.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from _io._TextIOBase:\n",
" | \n",
" | errors\n",
" | The error setting of the decoder or encoder.\n",
" | \n",
" | Subclasses should override.\n",
" | \n",
" | newlines\n",
" | Line endings translated so far.\n",
" | \n",
" | Only line endings translated during reading are considered.\n",
" | \n",
" | Subclasses should override.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from _io._IOBase:\n",
" | \n",
" | __del__(...)\n",
" | \n",
" | __enter__(...)\n",
" | \n",
" | __exit__(...)\n",
" | \n",
" | __iter__(self, /)\n",
" | Implement iter(self).\n",
" | \n",
" | __new__(*args, **kwargs) from builtins.type\n",
" | Create and return a new object. See help(type) for accurate signature.\n",
" | \n",
" | __next__(self, /)\n",
" | Implement next(self).\n",
" | \n",
" | fileno(self, /)\n",
" | Returns underlying file descriptor if one exists.\n",
" | \n",
" | OSError is raised if the IO object does not use a file descriptor.\n",
" | \n",
" | isatty(self, /)\n",
" | Return whether this is an 'interactive' stream.\n",
" | \n",
" | Return False if it can't be determined.\n",
" | \n",
" | readable(self, /)\n",
" | Return whether object was opened for reading.\n",
" | \n",
" | If False, read() will raise OSError.\n",
" | \n",
" | readlines(self, hint=-1, /)\n",
" | Return a list of lines from the stream.\n",
" | \n",
" | hint can be specified to control the number of lines read: no more\n",
" | lines will be read if the total size (in bytes/characters) of all\n",
" | lines so far exceeds hint.\n",
" | \n",
" | seek(...)\n",
" | Change stream position.\n",
" | \n",
" | Change the stream position to the given byte offset. The offset is\n",
" | interpreted relative to the position indicated by whence. Values\n",
" | for whence are:\n",
" | \n",
" | * 0 -- start of stream (the default); offset should be zero or positive\n",
" | * 1 -- current stream position; offset may be negative\n",
" | * 2 -- end of stream; offset is usually negative\n",
" | \n",
" | Return the new absolute position.\n",
" | \n",
" | seekable(self, /)\n",
" | Return whether object supports random access.\n",
" | \n",
" | If False, seek(), tell() and truncate() will raise OSError.\n",
" | This method may need to do a test seek().\n",
" | \n",
" | tell(self, /)\n",
" | Return current stream position.\n",
" | \n",
" | truncate(...)\n",
" | Truncate file to size bytes.\n",
" | \n",
" | File pointer is left unchanged. Size defaults to the current IO\n",
" | position as reported by tell(). Returns the new size.\n",
" | \n",
" | writable(self, /)\n",
" | Return whether object was opened for writing.\n",
" | \n",
" | If False, write() will raise OSError.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from _io._IOBase:\n",
" | \n",
" | __dict__\n",
"\n"
]
}
],
"source": [
"help(sys.stdout)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T01:28:55.666259Z",
"start_time": "2018-04-29T01:28:55.662026Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'a'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 调用deletetab\n",
"deletetab('\\ta')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T01:29:30.208184Z",
"start_time": "2018-04-29T01:29:24.089614Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9"
]
}
],
"source": [
"# 演示:flushPrint\n",
"import time, random\n",
"for i in range(10):\n",
" time.sleep(random.random())\n",
" flushPrint(i) "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:22:27.974338Z",
"start_time": "2019-06-08T08:22:27.925395Z"
},
"code_folding": [
9,
11
],
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"def readblocks(data):\n",
" copy = False\n",
" n = 0\n",
" block = []\n",
" chunk = defaultdict(lambda:[])\n",
" for i in data:\n",
" try:\n",
" if \"~~~~~~~~~~~~~~~~~~~~~~~~~~ #\" in i:\n",
" copy = True\n",
" elif \"文章编号:\" in i:\n",
" ids = i.replace('文章编号: ', '')\n",
" source = block[0].split('|')[0]\n",
" info = block[1]\n",
" title = deletetab(block[3]) # \n",
" body = [j for j in block[6:] if j != '\\n']\n",
" body = ' '.join(body)\n",
" body = deletetab(body)\n",
" body = '\"' + body + '\"'\n",
" line = '\\t'.join([ids, source, info, title, body])\n",
" chunk[ids] = line\n",
" block = []\n",
" n += 1\n",
" if n%10 == 0:\n",
" flushPrint(n)\n",
" copy = False\n",
" # copy must be here.\n",
" elif copy:\n",
" block.append(i)\n",
" except Exception as e:\n",
" print(i, e)\n",
" pass\n",
" return chunk"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:22:40.156812Z",
"start_time": "2019-06-08T08:22:40.152349Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"~~~~~~~~~~~~~~~~~~~~~~~~~~ #1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n",
"am730 | 2014-10-31 \\par\n",
"\n",
"A16| NEWS| C观点| By 施永青 \\par \n",
"\n",
"\n",
"\n",
"法治有整合社会功能 \\par\n",
"\n",
"\\par\n",
"\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\par\n",
"\n"
]
}
],
"source": [
"# 注意:标题和版面之间存在一个空行!所以title是block的第4个元素。\n",
"for i in range(1, 8):\n",
" print(news[i][:500])"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:22:54.481139Z",
"start_time": "2019-06-08T08:22:54.416996Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"710"
]
}
],
"source": [
"# 按block清洗新闻报道\n",
"news_result = readblocks(news_clean) "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:23:08.433080Z",
"start_time": "2019-06-08T08:23:08.428582Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"719"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 新闻的数量\n",
"len(news_result)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:23:12.433517Z",
"start_time": "2019-06-08T08:23:12.428573Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"['201410115306047 ',\n",
" '201410090050254 ',\n",
" '201410310050132 ',\n",
" '201410160290135 ',\n",
" '201410170040096 ']"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 查看字典的keys\n",
"list(news_result.keys())[:5]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:23:44.873031Z",
"start_time": "2019-06-08T08:23:44.868198Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'201410290050192 \\t文汇报 \\tB01| 财经新闻| 财经头条 \\t好友大挟仓 港股重夺三关 内地好消息提振 恒指劲弹377点 \\t\" 香港文汇报讯(记者 周绍基、裘毅)「沪港通」延迟对港股的影响只有一天,市场焦点已转至今日起的美联储局议息会议及内地的自贸区及国企改革,好友趁机挟淡仓,令昨日大市快速反弹,高开46点后升幅扩大,一举升穿10天线(23,192点)、20天线(23,198点)及250天牛熊线(23,176点),恒指全日收报23,520点,大涨377点或1.63%,盘中最多更曾升逾400点,成功收复周一的失地,成交也增至683亿元,出现「价量齐升」的好状况。分析师指出,A股爆升逾2%,是带动恒指大反弹的主因。 憧憬内地大力发展自由贸易区,加上对国企改革的期待,沪深两市昨日强劲反弹,股指涨幅均超2%。上证综指收报2,338点,涨幅2.07%,成交1,581亿元人民币,深成指收报7,988点,涨幅2.03%,成交1,752亿元人民币,创业板指报1,522点,涨幅2.01%。 国企改革料将展开 国指跑赢 四中全会闭幕,市场认为国企改革即将展开,其中中资金融股表现抢眼,令国指大幅跑赢大市,全日升2.3%至10,548点。本周四结算的期指表现活跃,即月期指升361点至23,579点,高水59点,成交合约达18.3万张,国指期货成交更达26.7万张。 耀才证券研究部经理植耀辉表示,港股大升主要受A股带动,但后市能否更进一步,他则认为上升的动力并不足够,相信只为好友挟高期指杀淡仓,当周四期指完成结算后,大市将会回复上落市格局。 美议息前夕 偷步炒延迟加息 他又指,昨日港股虽升近400点,但仍未突破横行区间,要港股再有突破,需要更多的利好消息,例如联储局议息会议提及延迟加息、「占中」行动有缓和迹象,或者沪港通有好消息等。 美国时间周二起联储局将一连两日议息,有市场分析认为,美国经济复苏步伐未稳,面对环球经济增长放缓甚至衰退,预料美联储会释出延迟加息的讯息,更有意见认为当局不排除会表达再启买债的考虑。有关对储局延迟加息的憧憬,为昨日大市提供炒作动力。(见另稿) 在大市上升下,昨日有26只熊证被杀,当中24只为恒指熊证,杀淡友一个措手不及。另一个令淡友跌眼镜的还包括港交所(0388),该股回升1.8%至169.2元,美银美林亦发报告唱好,指沪港通虽未有确实开通日期,美林相信,有关措施的延后只是暂时性,对年内开通沪港通仍充满信心。故此,港交所股价虽短期内受压,但长远仍给予港交所「买入」评级,目标价维持195元。 券商股也见反弹,第一上海(0227)及申银万国(0218)升5%,华富(0952)及新华汇富(0188)亦升逾4%,中州(1375)升3.8%。 蓝筹股方面,中移动(0941)升2.8%、腾讯(0700)涨1.7%带动大市。表现最突出的为百丽(1880),该股公布派中期息加特别息共派40分人民币,在高息下全日急升一成至9.32元。 四中全会甫闭幕,国企新一轮改革即展开,南车(1766)和北车(6199)宣布合并,两股昨日停牌,消息指本周六将有重大消息发布。市场人士料,该股复牌后,将掀起相关股份的炒作。 传人行放水 中资金融股受捧 近日盛传人行向股份制银行投放的千亿元人民币资金,料借此推动贷款回升,并对三农和小微贷款有所倾斜。中资金融股表现抢眼,工行(1398)、交行(3328)、建行(0939)、中行(3988)都升逾2%。平保(2318)、国寿(2628)亦分别升3.2%及2.5%、太保(2601)更弹升4%。 \"'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 查看字典的values\n",
"list(news_result.values())[90]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:23:58.126728Z",
"start_time": "2019-06-08T08:23:57.608043Z"
},
"scrolled": true,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ids | \n",
" source | \n",
" info | \n",
" title | \n",
" body | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 201410115306047 | \n",
" 置业家居 | \n",
" 020| 置业家居| 焦点热话| By 李伟航梁思恒 | \n",
" 淘大花园及德福花园 各录3宗交投 | \n",
" \" 至于九龙区,过往成交量较多的区域,如荔枝角、长沙湾及深水埗区沿线,... | \n",
"
\n",
" \n",
" 1 | \n",
" 201410090050254 | \n",
" 文汇报 | \n",
" A26| 人民政协专刊| 热心公益 | \n",
" 连任「潮企」掌门人 谂计升协会声望 | \n",
" \" 郑敬凯热心社会活动,身兼香港及内地多项公职,包括四川省海外联谊会常务理... | \n",
"
\n",
" \n",
" 2 | \n",
" 201410310050132 | \n",
" 文汇报 | \n",
" A15| 社团新闻 | \n",
" 中成药商会会董就职 黄楚恒膺会长 | \n",
" \" 香港文汇报讯(记者 解玲)中成药商会12周年会庆暨第七届会董会就职典礼... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ids source info title \\\n",
"0 201410115306047 置业家居 020| 置业家居| 焦点热话| By 李伟航梁思恒 淘大花园及德福花园 各录3宗交投 \n",
"1 201410090050254 文汇报 A26| 人民政协专刊| 热心公益 连任「潮企」掌门人 谂计升协会声望 \n",
"2 201410310050132 文汇报 A15| 社团新闻 中成药商会会董就职 黄楚恒膺会长 \n",
"\n",
" body \n",
"0 \" 至于九龙区,过往成交量较多的区域,如荔枝角、长沙湾及深水埗区沿线,... \n",
"1 \" 郑敬凯热心社会活动,身兼香港及内地多项公职,包括四川省海外联谊会常务理... \n",
"2 \" 香港文汇报讯(记者 解玲)中成药商会12周年会庆暨第七届会董会就职典礼... "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"news_list = [i.split('\\t') for i in news_result.values()]\n",
"df_news = pd.DataFrame(news_list,\n",
" columns= ['ids', 'source',\\\n",
" 'info', 'title', 'body'])\n",
"df_news.head(3)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-24T07:19:54.085577Z",
"start_time": "2018-04-24T07:19:54.076753Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"# 保存数据:将数据写入硬盘\n",
"with open('../data/zz-hk-2014-9-clean.txt','a') as p:\n",
" for record in news_result.values():\n",
" p.write(record+\"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T01:43:26.571011Z",
"start_time": "2018-04-29T01:43:26.541176Z"
},
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ids | \n",
" source | \n",
" info | \n",
" title | \n",
" body | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 201409015325665 | \n",
" 南华早报 | \n",
" EDT13| EDT | \n",
" Pain of stasis | \n",
" 没有文字档。 | \n",
"
\n",
" \n",
" 1 | \n",
" 201409055305251 | \n",
" 大公报 | \n",
" A20| 专版 | \n",
" 坚决支持和拥护 全国人大常委会对香港政改的决定 | \n",
" 一、本会坚决支持全国人大常委会关于香港特别行政区行政长官普选问题和201... | \n",
"
\n",
" \n",
" 2 | \n",
" 201409165304250 | \n",
" 大公报 | \n",
" B02| 经济.航运 | \n",
" 粤投1.8亿入股中超 | \n",
" 【大公报记者毛丽娟深圳十五日电】中国水业(01129)与粤海投资(002... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ids source info title \\\n",
"0 201409015325665 南华早报 EDT13| EDT Pain of stasis \n",
"1 201409055305251 大公报 A20| 专版 坚决支持和拥护 全国人大常委会对香港政改的决定 \n",
"2 201409165304250 大公报 B02| 经济.航运 粤投1.8亿入股中超 \n",
"\n",
" body \n",
"0 没有文字档。 \n",
"1 一、本会坚决支持全国人大常委会关于香港特别行政区行政长官普选问题和201... \n",
"2 【大公报记者毛丽娟深圳十五日电】中国水业(01129)与粤海投资(002... "
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 使用pandas读取数据,并查看。\n",
"import pandas as pd\n",
"df = pd.read_csv( '../data/zz-hk-2014-9-clean.txt', \n",
" sep = \"\\t\", names=['ids', 'source','info', 'title', 'body'])\n",
"df[:3]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"ExecuteTime": {
"end_time": "2019-06-08T08:24:59.075242Z",
"start_time": "2019-06-08T08:24:59.069078Z"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"['../data/occupycentral/zz-hk-2014-10.rtf',\n",
" '../data/occupycentral/zz-hk-2014-9.rtf']"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 使用os改变默认的工作路径\n",
"#import os\n",
"#os.chdir('../data/occupycentral/')\n",
"\n",
"# 使用glob读取某一类文件的所有名称\n",
"import glob\n",
"filenames = glob.glob('../data/occupycentral/*.rtf')\n",
"filenames"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T01:56:25.617281Z",
"start_time": "2018-04-29T01:56:25.387004Z"
},
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"../data/occupycentral/zz-hk-2014-10.rtf\n",
"710../data/occupycentral/zz-hk-2014-9.rtf\n",
"410"
]
}
],
"source": [
"for i in filenames:\n",
" print(i)\n",
" with open(i, encoding = 'gb18030', errors = 'ignore') as f: # for windows users: errors = 'ignore'\n",
" news = f.readlines()\n",
" news = [stringclean(n) for n in news]\n",
" news_result = readblocks(news)\n",
" with open('../data/zz-hk-all-clean2018.txt','a') as p:\n",
" for record in news_result.values():\n",
" p.write(record+\"\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-29T02:11:47.425356Z",
"start_time": "2018-04-29T02:11:47.418604Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"# 字节(Byte /bait/)\n",
"\n",
"计算机信息技术用于计量存储容量的一种计量单位,通常情况下一字节等于有八位, [1] 也表示一些计算机编程语言中的数据类型和语言字符。\n",
"- 1B(byte,字节)= 8 bit(见下文);\n",
"- 1KB=1000B;1MB=1000KB=1000×1000B。其中1000=10^3。\n",
"- 1KB(kilobyte,千字节)=1000B= 10^3 B;\n",
"- 1MB(Megabyte,兆字节,百万字节,简称“兆”)=1000KB= 10^6 B;\n",
"- 1GB(Gigabyte,吉字节,十亿字节,又称“千兆”)=1000MB= 10^9 B;"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"***\n",
"***\n",
"# 自学Pandas使用\n",
"\n",
"《Python Data Science Handbook》第三章 by Jake VanderPlas\n",
"\n",
"***\n",
"***\n",
"\n",
"https://github.com/computational-class/datascience/blob/gh-pages/4.datasci/notebooks/03.00-Introduction-to-Pandas.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# This is the End.\n",
"> Thank you for your attention."
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python [conda env:anaconda]",
"language": "python",
"name": "conda-env-anaconda-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 0,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": false,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {
"height": "48px",
"left": "1374px",
"top": "44.375px",
"width": "226px"
},
"toc_section_display": false,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 1
}