Setting freq of pandas DatetimeIndex after DataFrame creation

后端 未结 3 523
猫巷女王i
猫巷女王i 2021-02-12 12:03

Im using pandas datareader to get stock data.

import pandas as pd
import pandas_datareader.data as web
ABB = web.DataReader(name=\'ABB.ST\', 
                           


        
3条回答
  •  野性不改
    2021-02-12 12:28

    If need change frequency of index resample is for you, but then need aggregate columns by some functions like mean or sum:

    print (ABB.resample('d').mean())
    print (ABB.resample('d').sum())
    

    If need select another row use iloc with get_loc for find position of value in DatetimeIndex:

    print (ABB.iloc[ABB.index.get_loc('2001-05-09') + 1])
    Open            188.00
    High            192.00
    Low             187.00
    Close           191.00
    Volume       764200.00
    Adj Close       184.31
    Name: 2001-05-10 00:00:00, dtype: float64
    

提交回复
热议问题