[Python] Slice the data with pandas

Source: Internet
Author: User

For example we have the dataframe like this:

                   SPY        AAPL         IBM        GOOG         GLD2017-01-03  222.073914  114.311760  160.947433  786.140015  110.4700012017-01-04  223.395081  114.183815  162.940125  786.900024  110.8600012017-01-05  223.217606  114.764473  162.401047  794.020020  112.5800022017-01-06  224.016220  116.043915  163.200043  806.150024  111.7500002017-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         GLD2017-01-03  222.073914  114.311760  160.947433  786.140015  110.4700012017-01-04  223.395081  114.183815  162.940125  786.900024  110.8600012017-01-05  223.217606  114.764473  162.401047  794.020020  112.5800022017-01-06  224.016220  116.043915  163.200043  806.150024   111.7500002017-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 20 17-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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.