When I query a service through their API for daily data, they throw in a time portion which is equal to whatever time the query was made. So my pandas dataframe looks like this when I called the function at 14:54:36 -
2018-05-16 14:54:36 1024.75 1008.25 ... 39221 242897
2018-05-17 14:54:36 1017.00 1002.00 ... 35361 241132
2018-05-18 14:54:36 1015.75 1002.75 ... 49090 242938
2018-05-21 14:54:36 1034.50 1020.75 ... 56950 243316
2018-05-22 14:54:36 1043.75 1028.50 ... 49724 247874
2018-05-23 14:54:36 1049.00 1036.25 ... 46256 253609
2018-05-24 14:54:36 1059.75 1047.00 ... 65352 259617
As this is daily data, the time portion is useless. When I do:
data = pd.read_csv(StringIO(data), index_col=0, header=None,names=['High','Low','Open','Close','Volume','OpenInterest'])
data.index = pd.to_datetime(data.index,format="%Y-%m-%d")
The format doesn't seem to work. The DateTime index still contains time. Any idea how I can remove the time portion?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…