简体   繁体   English

如何从特定行和列 python 的单元格中检索值?

[英]how to retrieve the value from a cell of specific row and column 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

I want to retrieve value from 2020-04-20(todays date) column of 3rd row from the above.This is the result of我想从上面的第 3 行的 2020-04-20(今天日期)列中检索值。这是结果

print(data.columns)    

I tried using get_value and.at.It didnt work我尝试使用 get_value 和.at。它没有用

print(data.columns)打印(数据。列)

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)

You need to convert your index into datetime object.您需要将索引转换为datetime时间 object。 Currently its string.目前它的字符串。 you can change index into datetime:您可以将索引更改为日期时间:

df.index = pd.to_datetime(df.index)

After that it should work.之后它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 如何在不使用 pandas 的情况下,根据同一行中的其他单元格值从 csv 文件中检索特定的单元格值? - Python How to retrieve a specific cell value from a csv file based on other cell values in the same row without using pandas? 如何使用 Python Pandas 从 1 行中的特定列获取值? - How to get value from specific column in 1 row using Python Pandas? 如何从 Python 中每行的特定值获取列名 - How to get column name from specific value per row in Python 如何删除指向 dataframe 中具有特殊字符的单元格的特定行和列 Python? - How can I delete a specific row and column pointing to a cell from a dataframe having a special character in Python? 如何通过python中的单元格值获取列数或行数 - how to get column or row number by cell value in python 基于列单元格值如何使用 python 从字符串中提取特定的字符编号 - based on column cell value how to extract specific no# of character from string using python 使用 Python 从 csv 文件中的特定行号和列号获取值 - Getting a value from a specific row and column number in a csv file with Python 如何从文本文件中读取特定的行和列,以及如何使用python决定数值? - How to read a specific row and column from a text file and base decision on numeric value with python? 如何通过python知道数据框中特定值的行名和列名? - how to know row name and column name of a specific value in a dataframe by python? Python Bs4:如何根据该行的特定“td”值检索表中的行 - Python Bs4: How to retrieve row in table based on specific 'td' value that row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM