欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > PPTX文档下载
    分享到微信 分享到微博 分享到QQ空间

    Python大数据编程.pptx

    • 资源ID:18715415       资源大小:2.11MB        全文页数:100页
    • 资源格式: PPTX        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Python大数据编程.pptx

    1、Python大数据编程,4数据分析,3数据描述,1数据收集,2数据整理,大数据处理过程,2,便捷数据获取,Python大数据编程,用Python获取数据,本地数据如何获取?文件的打开,读写和关闭文件打开读文件写文件文件关闭,4,用Python获取数据,网络数据如何获取?抓取网页,解析网页内容,urllib,urllib2,httplib,httplib2,5,Python 3中被urllib.request代替,Python 3中被http.client代替,yahoo财经数据,http:/t,利用urllib库获取yahoo财经数据,File#Filename:dji.py import u

    2、rllib import redBytes=urllib.request.urlopen(http:/dStr=dBytes.decode(GBK)#在python3中urllib.read()返回bytes对象而非str,语句功能是将dBytes转换成Strm=re.findall(.*?)(.*?).*?(.*?).*?,dStr)if m:print m print n print len(m)else:print not match,数据形式,包含多个字符串(dji)AXP,American Express Company,86.40BA,The Boeing Company,122.

    3、24CAT,Caterpillar Inc.,99.44CSCO,Cisco Systems,Inc.,23.78CVX,Chevron Corporation,115.91,便捷网络数据,是否能够简单方便并且快速的方式获得雅虎财经上各上市公 司股票的历史数据?,File#Filename:quotes.pyfrom matplotlib.finance import quotes_historical_yahoo from datetime import dateimport pandas as pdtoday=date.today()start=(today.year-1,today.mo

    4、nth,today.day)quotes=quotes_historical_yahoo_ochl(AXP,start,today)df=pd.DataFrame(quotes)print df,函数目前更新为 quotes_historical_ yahoo_ochl,便捷网络数据,quotes的内容,日期,收盘价,开盘价,最高价,最低价,成交量,便捷网络数据,自然语言工具包NLTK,古腾堡语料库布朗语料库路透社语料库网络和聊天文本,from nltk.corpus import gutenberg import nltk,print gutenberg.fileids(),uausten-

    5、emma.txt,uausten-persuasion.txt,uausten-sense.txt,ubible-kjv.txt,ublake-poems.txt,ubryant-stories.txt,uburgess-busterbrown.txt,ucarroll-alice.txt,uchesterton-ball.txt,uchesterton-brown.txt,uchesterton-thursday.txt,uedgeworth-parents.txt,umelville-moby_dick.txt,umilton-paradise.txt,ushakespeare-caesa

    6、r.txt,ushakespeare-hamlet.txt,ushakespeare-macbeth.txt,uwhitman-leaves.txt texts=gutenberg.words(shakespeare-hamlet.txt)u,uThe,uTragedie,uof,uHamlet,uby,.,Source,brown,需要先执行nltk.download()下载某一个或多个包,若下,载失败,可以在官网(http:/www.nltk.org/nltk_data/),单独下载后放到本地python目录的nltk_datacorpora下,数据准备,Python大数据编程,数据形式,

    7、30支成分股(dji)股票数据的逻辑结构,美国运通公司(quotes)股票详 细数据的逻辑结构,数据整理,quotes数据加属性名File#Filename:quotesproc.py from matplotlib.finance import quotes_historical_yahoo_ochl from datetime import date import pandas as pdtoday=date.today()start=(today.year-1,today.month,today.day)quotes=quotes_historical_yahoo_ochl(AXP,st

    8、art,today)fields=date,open,close,high,low,volume quotesdf=pd.DataFrame(quotes,columns=fields)print quotesdf,数据整理,dji数据:加属性 名,code,AXP,quotes数据:加属性名,数据整理,用1,2,作为索引,quotesdf=pd.DataFrame(quotes,columns=fields),quotesdf=pd.DataFrame(quotes,index=range(1,len(quotes)+1),columns=fields),数据整理,如果可以直接用date作为

    9、索引,quotes的时间能否转换成常规形式(如下图中的效果)?,Source from datetime import date firstday=date.fromordinal(735190)lastday=date.fromordinal(735551)firstdaydatetime.date(2013,11,18)lastday datetime.date(2014,11,14),时间序列,#Filename:quotesproc.pyfrom matplotlib.finance import quotes_historical_yahoo_ochlfrom datetime im

    10、port date from datetime import datetime import pandas as pdtoday=date.today()start=(today.year-1,today.month,today.day)quotes=quotes_historical_yahoo_ochl(AXP,start,today)fields=date,open,close,high,low,volume,list1=for i in range(0,len(quotes):x=date.fromordinal(int(quotesi0)y=datetime.strftime(x,%

    11、Y-%m-%d)list1.append(y),quotesdf=pd.DataFrame(quotes,index=list1,columns=fields),quotesdf=quotesdf.drop(date,axis=1)print quotesdf,File,转换成常规时间,转换成固定格式,删除原date列,创建时间序列,import pandas as pd dates=pd.date_range(20141001,periods=7)dates2014-10-01,.,2014-10-07Length:7,Freq:D,Timezone:None import numpy as

    12、 np dates=pd.DataFrame(np.random.randn(7,3),index=dates,columns=list(ABC)datesABC 2014-10-01 1.302600-1.214708 1.4116282014-10-02-0.512343 2.277474 0.4038112014-10-03-0.788498-0.217161 0.1732842014-10-04 1.042167-0.453329-2.1071632014-10-05-1.628075 1.663377 0.9435822014-10-06-0.091034 0.335884 2.45

    13、54312014-10-07-0.679055-0.865973 0.2469707 rows x 3 columns,Source,数据显示,Python大数据编程,数据显示,djidf,quotesdf,数据显示,显示方式:显示索引显示列名显示数据的值显示数据描述,数据显示,Source quotesdf.indexIndex(u2013-11-18,u2013-11-19,u2013-11-20,u2013-11-21,u2013-11-22,u2013-11-25,u2013-11-26,u2013-11-27,-04-08,u2014-04-09,u2014-04-10,u2014-

    14、04-11,.,dtype=object),索引的格式,数据显示,djidf.head(5),code,name,0AXP American Express Company,1BA,2CAT,CSCOCVX,The Boeing CompanyCaterpillar Inc.Cisco Systems,Inc.Chevron Corporation,lasttrade90.67128.86101.3426.32116.32,5 rows x 3 columns djidf.tail(5),code,namelasttrade,25UTX United Technologies Corporat

    15、ion,26VVisa Inc.,27VZ,Verizon Communications Inc.,WMTXOM,Wal-Mart Stores Inc.Exxon Mobil Corporation,107.45248.8451.5082.9695.09,5 rows x 3 columns,Source,df:5,df25:,显示方式:,显示行 专用方式 切片,查看道琼斯工业 股中前5只和后 5只的股票基本 信息?,数据选择,Python大数据编程,数据选择,选择方式:选择行选择列选择区域筛选(条件选择),数据选择,5 rows x 5 columns,Source quotesdfu20

    16、13-12-02:u2013-12-06,选择方式:,选择行 切片 索引,美国运通公司 2013年12月2日 至2013年12月6 日间的股票交易 信息?,数据选择,AXP BA CAT,01229XOM,Name:code,dtype:object djidf.code,01,AXP BA,CAT,229XOM,Name:code,dtype:object,Source djidfcode,选择方式:,选择列 列名,不支持djidfcode,lasttrade djidfcode:lasttrade,道琼斯工业股公 司代码?,数据选择,选择方式:,行、列 标签label(loc),5 row

    17、s x 3 columns djidf.loc:,code,lasttradecodelasttrade,0AXP,1BA,90.67128.862CAT101.3429XOM95.09,Source djidf.loc1:5,道琼斯工业股中 标号是1至5的股 票信息以及所有 股票的代码和最 近一次交易价?,30 rows x 2 columns,数据选择,选择方式:,行和列的区域标签label(loc)单个值at,3 CSCO,codelasttrade1BA128.862CAT101.3426.324CVX116.325DD70.80,5 rows x 2 columns djidf.lo

    18、c1,lasttrade128.86 djidf.at1,lasttrade 128.86,Source djidf.loc1:5,code,lasttrade,道琼斯工业股中标 号是1至5的股票代 码和最近一次交易 价?标号是1的股票 的最近一次交易价?,数据选择,选择方式:,行、列和区域,用iloc(位置),取某个值,iat,djidf.loc1:5,code,lasttrade,2CAT,CSCOCVX,codelasttrade 1BA128.86101.3426.32116.325DD70.80,Source,djidf.loc1,lasttrade 128.86 djidf.at1

    19、,lasttrade128.86,Source,djidf.iloc1,2128.86 djidf.iat1,2 128.86,Source,数据选择,quotesdfquotesdf.index=u2014-01-01openclosehigh,lowvolume,221 rows x 5 columns quotesdf(quotesdf.index=u2014-01-01)&(quotesdf.close=95),3 rows x 5 columns,Source,美国运通公司 2014年的股票 信息?进一步 寻找美国运通 公司2014年收 盘价大于等于 95的记录?,选择方式:条件筛选

    20、,简单统计与处理,Python大数据编程,简单统计与筛选,1The Boeing Company8The Goldman Sachs Group,Inc.10International Business Machines Corporation163M Company26Visa Inc.,Name:name,dtype:object,Source djidf.mean(columns=lasttrade)lasttrade91.533667dtype:float64 djidfdjidf.lasttrade=120.name,求道琼斯工业股 中30只股票最近 一次成交价的平 均值?股票最近

    21、一次成交价大于 等于120的公司 名?,简单统计与筛选,Source len(quotesdfquotesdf.close quotesdf.open)131 len(quotesdf)-131 120,统计美国运通公 司近一年股票涨 和跌分别的天数?,统计美国运通公 司近一年相邻两 天收盘价的涨跌 情况?,Source status=np.sign(np.diff(quotesdf.close)statusarray(1.,-1.,1.,-1.,1.,1.,1.,1.,-1.,-1.,-1.,1.,1.,-1.,-1.,-1.)statusnp.where(status=1.).size 1

    22、30 statusnp.where(status=-1.).size120,排序,djidf.sort(columns=lasttrade)code,name lasttrade,3CSCO,7GE,Cisco Systems,Inc.General Electric Company,26.3226.46,30 rows x 3 columns djidf.sort(columns=lasttrade)27:.name,10International Business Machines Corporation8The Goldman Sachs Group,Inc.26Visa Inc.,Na

    23、me:name,dtype:object,Source,按最近一次成交,价对30只道琼斯 工业股股票进行 排序。根据排序 结果列出前三甲 公司名。,可以添加sort()函数的ascending,属性控制顺序/逆序排序,默 认该属性=True,即顺序排列,DataFrame的sort()函数已不推荐使用,相同功能推,荐使用sort_index()函数,计数统计,21 rows x 5 columns len(t)21,Source t=quotesdf(quotesdf.index=2014-01-01)&(quotesdf.index t,统计2014年1月份的股票开盘天数?,计数统计,统计近

    24、一年每个月的股票开盘天数?,GROUPING,Python大数据编程,分组,Grouping的顺序SplittingApplyingCombining,分组,统计近一年每个月的股票开盘天数?,分组,统计近一年每个月的总成交量?,tempdf.groupby(month).sum().volume month,Source,mean()min()max(),11,67906300,12,67589400,Name:volume,dtype:float64,分组,如果更高效统计近一年每个月的总成交量?,12310,1048740007617380071488400120822100,Source

    25、g=tempdf.groupby(month)gvolume=gvolume print gvolume.sum()month,11,67906300,12,67589400,Name:volume,dtype:float64,MERGE,Python大数据编程,合并,Merge的形式Append加行到DataFrameConcat连接pandas对象JoinSQL类型的连接,Append,lowvolume,2 rows x 5 columns q=quotesdfu2014-01-01:u2014-01-05 q,openclosehighlowvolume,2014-01-02 89.9

    26、24438 88.49 90.102506 88.420751 51120002014-01-03 88.186377 88.77 89.106325 87.671998 38885002 rows x 5 columns p.append(q),4 rows x 5 columns,Source p=quotesdf:2 popenclosehigh,把美国运通公司 2014年1月1日 至2014年1月5 日间的股票交易 信息合并到近一 年中前两天的股 票信息中?,Concat,将美国运通 公司近一年 股票数据中 的前5个和 后5个合并。,open closehighlowvolume mo

    27、nth,2013-11-18 81.954487 81.45 82.083082 81.271946 3104800,11,11,2014-11-17 90.240000 90.13 90.260000 89.650000 262050020 rows x 6 columns,Source pieces=tempdf:5,tempdflen(tempdf)-5:pd.concat(pieces),Concat,两个不同逻辑结构 的对象能否连接?,6 rows x 6 columns,Source piece1=quotesdf:3 piece2=tempdf:3 pd.concat(piece

    28、1,piece2,ignore_index=True),Join,Join,将美国运通公司 和可口可乐公司 近一年中每个月 的交易总量表(包含公司代码)与30只道琼斯 成分股股票信息 合并。,code|name|month|volumes,Join,code,name lasttrade,volume month,24 rows x 5 columns pd.merge(djidf,AKdf,on=code).drop(lasttrade,axis=1),Source pd.merge(djidf,AKdf,on=code),merge函数的参数,条件,Python大数据编程,if 语句,Fi

    29、le#Filename:ifpro.py sd1=3sd2=3if sd1=sd2:print the squares area is:%d%(sd1*sd2),if expression:expr_true_suite,语 法,条件表达式:,比较运算符成员运算符逻辑运算符,expression,expression 条 件 为True时执行的代码块代码块必须缩进(通 常为4个空格),expr_true_suite,else 语句,if expression:expr_true_suiteelse:expr_false_suite,语 法,expression 条 件 为 False 时 执

    30、行 的 代 码 块代码块必须缩进else语句不缩进,expr_false_suite,File#Filename:elsepro.pysd1=int(raw_input(the first side:)sd2=int(raw_input(the second side:)if sd1=sd2:print the squares area is:%d%(sd1*sd2)else:print the rectangles area is:%d%(sd1*sd2)Input and Outputthe first side:4 the second side:4the squares area is

    31、:16,elif 语句,if expression:expr_true_suiteelif expression2:expr2_true_suite:elif expressionN:exprN_true_suiteelse:none_of_the_above_suite,语 法,expression2为True时 执行的代码块,expr2_true_suite,expressionN 为 True时执行的代码块,exprN_true_suite,none_of_the_above_s uite是以上所有条件都 不满足时执行的代码块,else,elif 语句,File#Filename:eli

    32、fpro.pyk=raw_input(input the index of shape:)if k=1:print circle elif k=2:print ovalelif k=3:print rectangle elif k=4:print triangle else:print you input the invalid number,Input andOutputinput the index of shape:3rectangle,Input andOutputinput the index of shape:8you input the invalid number,条件嵌套,F

    33、ile#Filename:ifnestpro.pyk=raw_input(input the index of shape:)if k=1:print circleelif k=2:print oval elif k=3:sd1=int(raw_input(the first side:)sd2=int(raw_input(:the second side)if sd1=sd2:print the squares area is:%d%(sd1*sd2)else:print the rectangles area is:%d%(sd1*sd2)print rectangleelif k=4:print triangleelse:print you input the invalid number,同等缩进为同一条件结构Input andOutputinput the index of sh


    注意事项

    本文(Python大数据编程.pptx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开