python - 如何从特定行和列python的单元格中检索值?
问题描述
2020-04-13
2020-04-14
2020-04-15
2020-04-16
2020-04-17
2020-04-20
2020-04-21
2020-04-22
2020-04-23
2020-04-24
2020-04-27
2020-04-28
2020-04-29
2020-04-30
2020-05-01
2020-05-04
2020-05-05
2020-05-06
2020-05-07
2020-05-08
2020-05-11
2020-05-12
2020-05-13
2020-05-14
2020-05-15
2020-05-18
2020-05-19
2020-05-20
2020-05-21
2020-05-22
我想从上面的第 3 行的 2020-04-20(今天日期)列中检索值。这是结果
print(data.columns)
我尝试使用 get_value 和 .at。它没有用
打印(数据。列)
for i in data.columns:
convert_date=i.date()#converting to date type
if date.today()==convert_date:#comparing todays date
print(date.today())
print(data.at[3,date.today()])#throws KeyError: datetime.date(2020, 4, 20)
解决方案
您需要将索引转换为datetime
对象。目前它的字符串。您可以将 index 更改为 datetime :
df.index = pd.to_datetime(df.index)
之后它应该工作。
推荐阅读
- node.js - 在我的基于 NodeJS 的 lambda 中,无法在回调 getSignedUrl 时调用 AWS SES sendEmail 函数
- hibernate - 使用 AND/OR 组合的休眠条件
- java - 我的快速排序方法有一个基本案例,但我仍然收到堆栈溢出错误?
- node.js - 如何使用 Sequelize 在表(复合键)之间创建关联?
- sql - T-sql,运行名称存储在字符串变量中的函数......使用 exec 之类的东西......并捕获返回值
- php - 使用 natsort() 对函数的返回值进行排序
- computer-science - 每当通过汇编(RISC-V)在字符串中出现双辅音时,如何打印减号(-)?
- python - Python递归函数删除无
- android - 在 Android 模拟器中录制闪烁
- c - 使用 GDB 和 VScode 调试器无法通过 printf