Python中的日期时间格式用于在数据框中查找列

2024-04-19 08:05:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我应该如何将日期格式从01/13更改为1/13,两者在python中都应该是日期格式? 我的数据框如下所示: enter image description here

而我的代码的预期部分如下所示,我希望通过行索引和列索引查找特定单元格,其中我得到了行索引部分,但列索引没有出现,并显示此错误:

formated_day=(date.today() - timedelta(i)).strftime("%m/%d")
row_number=dataframe_wsheet.loc[dataframe_wsheet[""]==name].index.values
print(row_number)

[5]

dataframe_wsheet.loc[:,formated_day]

它显示了这个错误:

KeyError: 'the label [01/13] is not in the [columns]'

Tags: the数据代码numberdataframetodaydate格式