For example we have dataframe like this:

                   SPY        AAPL         IBM        GOOG         GLD
2017-01-03 222.073914 114.311760 160.947433 786.140015 110.470001
2017-01-04 223.395081 114.183815 162.940125 786.900024 110.860001
2017-01-05 223.217606 114.764473 162.401047 794.020020 112.580002
2017-01-06 224.016220 116.043915 163.200043 806.150024 111.750000
2017-01-09 223.276779 117.106812 161.390244 806.650024 112.669998
...

Now we only we want to get highlighted part:

                   SPY        AAPL         IBM        GOOG         GLD
2017-01-03 222.073914 114.311760 160.947433 786.140015 110.470001
2017-01-04 223.395081 114.183815 162.940125 786.900024 110.860001
2017-01-05 223.217606 114.764473 162.401047 794.020020 112.580002
2017-01-06 224.016220 116.043915 163.200043 806.150024 111.750000
2017-01-09 223.276779 117.106812 161.390244 806.650024 112.669998

We can use Dataframe.ix[] method to get date related index data from the list.

if __name__ == '__main__':
data=get_data()
data=data.ix['2017-12-01':'2017-12-15', ['IBM', 'GOOG']]
print(data)
"""
IBM GOOG
2017-12-01 154.759995 1010.169983
2017-12-04 156.460007 998.679993
2017-12-05 155.350006 1005.150024
2017-12-06 154.100006 1018.380005
2017-12-07 153.570007 1030.930054
2017-12-08 154.809998 1037.050049
2017-12-11 155.410004 1041.099976
2017-12-12 156.740005 1040.479980
2017-12-13 153.910004 1040.609985
2017-12-15 152.500000 1064.189941
"""

[Python] Slice the data with pandas的更多相关文章

  1. [Python] Normalize the data with Pandas

    import os import pandas as pd import matplotlib.pyplot as plt def test_run(): start_date='2017-01-01 ...

  2. 一句Python,一句R︱pandas模块——高级版data.frame

    先学了R,最近刚刚上手python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句python,对应写一句R. pandas可谓如雷贯耳,数据处理神器. 以下符号: = ...

  3. Seven Python Tools All Data Scientists Should Know How to Use

    Seven Python Tools All Data Scientists Should Know How to Use If you’re an aspiring data scientist, ...

  4. arcgis python arcpy add data script添加数据脚本

    arcgis python arcpy add data script添加数据脚本mxd = arcpy.mapping.MapDocument("CURRENT")... df ...

  5. Python slice() 函数

    Python slice() 函数  Python 内置函数 描述 slice() 函数实现切片对象,主要用在切片操作函数里的参数传递. 语法 slice 语法: class slice(stop) ...

  6. [Machine Learning with Python] My First Data Preprocessing Pipeline with Titanic Dataset

    The Dataset was acquired from https://www.kaggle.com/c/titanic For data preprocessing, I firstly def ...

  7. Python数据科学安装Numby,pandas,scipy,matpotlib等(IPython安装pandas)

    Python数据科学安装Numby,pandas,scipy,matpotlib等(IPython安装pandas) 如果还没有本地安装Python.IPython.notebook等请移步 上篇Py ...

  8. 用pandas进行数据清洗(二)(Data Analysis Pandas Data Munging/Wrangling)

    在<用pandas进行数据清洗(一)(Data Analysis Pandas Data Munging/Wrangling)>中,我们介绍了数据清洗经常用到的一些pandas命令. 接下 ...

  9. Python For Data Analysis -- Pandas

    首先pandas的作者就是这本书的作者 对于Numpy,我们处理的对象是矩阵 pandas是基于numpy进行封装的,pandas的处理对象是二维表(tabular, spreadsheet-like ...

随机推荐

  1. FCC高级编程篇之Exact Change

    Exact Change Design a cash register drawer function checkCashRegister() that accepts purchase price ...

  2. 操作Map

    ///操作Map Map<String,Object> userInfo = new HashMap(); userInfo.put("uid", adUserEnti ...

  3. maven使用技巧

    转:MAVEN常用命令 Maven库: http://repo2.maven.org/maven2/ Maven依赖查询: http://mvnrepository.com/ Maven常用命令: 1 ...

  4. shell 特殊字符

    shell 基础 # 当做注释的比较多 : 命令分隔符,在同一行上写两个或两个以上的命令 :: 是case 代码块的结束符 . 点作为文件名的一部分 隐藏文件 目录名 点是正则表达式中的匹配字符 '' ...

  5. 紫书 例题8-5 UVa11054(等价转换)

    这道题用到了等价转换的思想 所有要运到a1的酒, 都要经过a2, 所以不如把a2的值改成a1+a2,然后依次以此类推. #include<cstdio> #include<cmath ...

  6. CodeVS 1789 最大获利

    1789 最大获利 2006年NOI全国竞赛  时间限制: 2 s  空间限制: 128000 KB  题目等级 : 大师 Master       题目描述 Description 新的技术正冲击着 ...

  7. zjnu(1181)——石子合并

    这道题算是最简单的区间dp了..非常久之前写的,搞懂原理了就1A. 传送门:problem_id=1181">http://acm.zjnu.edu.cn/CLanguage/show ...

  8. C&C控制服务的设计和侦测方法综述——DDoS攻击,上传从宿主机偷窃的到的信息,定时给感染机文件加密勒索等。

    这篇文章总结了一些我在安全工作里见到过的千奇百怪的C&C控制服务器的设计方法以及对应的侦测方法,在每个C&C控制服务先介绍黑帽部分即针对不同目的的C&C服务器设计方法,再介绍白 ...

  9. List operations

    The + operator concatenates lists: Similarly, the * operator repeats a list a given number of items: ...

  10. channels2.X 学习笔记

    - No module named 'asgiref.sync' 报错解决: # 报错原因: """ django版本过低, 卸载最新版本的 channels 使用2.x ...