[Python] Slice the data with pandas
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的更多相关文章
- [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 ...
- 一句Python,一句R︱pandas模块——高级版data.frame
先学了R,最近刚刚上手python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句python,对应写一句R. pandas可谓如雷贯耳,数据处理神器. 以下符号: = ...
- 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, ...
- arcgis python arcpy add data script添加数据脚本
arcgis python arcpy add data script添加数据脚本mxd = arcpy.mapping.MapDocument("CURRENT")... df ...
- Python slice() 函数
Python slice() 函数 Python 内置函数 描述 slice() 函数实现切片对象,主要用在切片操作函数里的参数传递. 语法 slice 语法: class slice(stop) ...
- [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 ...
- Python数据科学安装Numby,pandas,scipy,matpotlib等(IPython安装pandas)
Python数据科学安装Numby,pandas,scipy,matpotlib等(IPython安装pandas) 如果还没有本地安装Python.IPython.notebook等请移步 上篇Py ...
- 用pandas进行数据清洗(二)(Data Analysis Pandas Data Munging/Wrangling)
在<用pandas进行数据清洗(一)(Data Analysis Pandas Data Munging/Wrangling)>中,我们介绍了数据清洗经常用到的一些pandas命令. 接下 ...
- Python For Data Analysis -- Pandas
首先pandas的作者就是这本书的作者 对于Numpy,我们处理的对象是矩阵 pandas是基于numpy进行封装的,pandas的处理对象是二维表(tabular, spreadsheet-like ...
随机推荐
- 1,http协议的细节部分学习
http协议(80端口)https(443端口) 主要是一直对三次握手模模糊糊,并且抓包的时候不知道那些Accept.User-Agent什么意思,就仔细找课程学了一下. 学习简介: 1,涉及工具(w ...
- 详解JavaScript中的原型和继承-转自颜海镜大大
本文将会介绍面向对象,继承,原型等相关知识,涉及的知识点如下: 面向对象与继承 CEOC OLOO 臃肿的对象 原型与原型链 修改原型的方式 面向对象与继承 最近学习了下python,还写了篇博文&l ...
- Springboot设置跨域的三种方式
方式一(精细配置) 在需要跨域的整个Controller或者单个方法上添加@CrossOrigin注解 方式二(全局配置) @Configuration public class WebMvcConf ...
- VB学习笔记(一)VB操作字符串
在vb中 dim a# 定义a变量为双精度型变量~ #是类型符 % 整型 & 长整型 !单精度 $ 字符型 VB中strconv 的作用 StrConv("要转换的字符串" ...
- Linux Eslint 命令行
Linux 命令行 ls : 查看所有文件 ls -la : 编列文件并展示权限 sudo chmod 777 -R 文件名 : 文件权限升级 cp : 复制 cp file_na ...
- 《virtual san 最佳实践》节选 Virtual SAN的发展与现状
Virtual SAN的发展与现状Virtual SAN已经迭代更新到第四代,即Virtual SAN 6.2.通过三次主版本迭代,Virtual SAN已经成为一款非常成熟的软件定义存储软件.在此, ...
- 洛谷 P1070 道路游戏
设为第i秒获得的最大值 表示从当前世界是j,从pos走k步到当前点i的最大价值 注意这里的sum可以利用前面的值逐步累加. 我开始做的时候没有想到这一点单独求,然后就超时了. 同时要注意循环的循序问题 ...
- OpenResty.spec
Name: openresty Version: 1.13.6.1 Release: 2%{?dist} Summary: OpenResty, scalable web platform by ex ...
- hadoop hdfs空间满后重新启动不了
server检查的时候,发现存在HDFS上的文件无法同步.再发现hadoop停掉了. 进行重新启动,重新启动不成功. 查看hadoop日志: 2014-07-30 14:15:42,025 INFO ...
- UVA 11020 - Efficient Solutions(set)
UVA 11020 - Efficient Solutions 题目链接 题意:每个人有两个属性值(x, y).对于每个人(x,y)而言,当有还有一个人(x', y'),假设他们的属性值满足x' &l ...