【发布时间】:2020-12-14 23:55:05
【问题描述】:
我可以从here 看到如何从日期时间索引中迭代日期列表。但是,我想使用以下方法定义日期范围:
my_df['Some_Column'].first_valid_index()
和
my_df['Some_Column'].last_valid_index()
我的尝试如下所示:
for today_index, values in range(my_df['Some_Column'].first_valid_index() ,my_df['Some_Column'].last_valid_index()):
print(today_index)
但是我收到以下错误:
TypeError: 'Timestamp' object cannot be interpreted as an integer
我如何通知循环限制到这些特定日期?
【问题讨论】:
-
答案已编辑,
date_range返回 DatetimeIndex,所以需要for val in r:,在您的update中使用today_indexinstaedtoday_index, values
标签: python pandas dataframe loops datetime