作家
登录

用Python做股市数据分析(一)

作者: 来源: 2017-07-07 08:50:15 阅读 我要评论

for each period specified by stick input 
  •  
  •     transdat = dat.loc[:,["Open""High""Low""Close"]] 
  •  
  •     if (type(stick) == str): 
  •  
  •         if stick == "day"
  •  
  •             plotdat = transdat 
  •  
  •             stick = 1 # Used for plotting 
  •  
  •         elif stick in ["week""month""year"]: 
  •  
  •             if stick == "week"
  •  
  •                 transdat["week"] = pd.to_datetime(transdat.index).map(lambda x: x.isocalendar()[1]) # Identify weeks 
  •  
  •             elif stick == "month"
  •  
  •                 transdat["month"] = pd.to_datetime(transdat.index).map(lambda x: x.month) # Identify months 
  •  
  •             transdat["year"] = pd.to_datetime(transdat.index).map(lambda x: x.isocalendar()[0]) # Identify years 
  •  
  •             grouped = transdat.groupby(list(set(["year",stick]))) # Group by year and other appropriate variable 
  •  
  •             plotdat = pd.DataFrame({"Open": [], "High": [], "Low": [], "Close": []}) # Create empty data frame containing what will be plotted 
  •  
  •             for namegroup in grouped: 
  •  
  •                 plotdat = plotdat.append(pd.DataFrame({"Open"group.iloc[0,0], 
  •  
  •                                             "High"max(group.High), 
  •  
  •                                             

      推荐阅读

      WOT讲师杨钊:人工智能将在不同应用场景逐步落地

    【51CTO.com原创稿件】由51CTO主办的WOTA2017全球立异技巧峰会将于2017年7月21日拉开帷幕。本次峰会,将环绕机>>>详细阅读


    本文标题:用Python做股市数据分析(一)

    地址:http://www.17bianji.com/lsqh/36070.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)