【发布时间】:2014-09-21 16:21:40
【问题描述】:
我正在阅读一个日终价格 csv 文件并使用日期列来索引数据框。我想检查最后一条记录的日期。我得到了索引值位置,但还没有弄清楚如何获取实际日期。
CSV 文件的格式为 Date、Open、High、Low、....
这里的日期格式为 2014-07-28。
import pandas as pd
df = pd.read_csv('c:/datafile.csv', index_col='Date')
lastrec = len(df.index) -1
# how to get 'Date' Value for this last record?
df.iloc[lastrec]
# gives me the Open, High, .... columns and values
df.iloc[lastrec].index
# gives me the list of columns
我所有的其他想法都给了我错误。
通过这个项目仍在学习 Python 和 Pandas。
如何从最后一条记录中获取索引值(DATE)?
【问题讨论】:
-
您应该发布您的编辑作为答案,然后接受它