Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Key error when trying to get a value in a Pandas Dataframe

I have a pandas dataframe df that has a column with the name "datetime". Now I would like to get a specific value from it. I tried the solutions suggested here How to get a value from a cell of a dataframe? but I always get an "KeyError: ‘datetime’"

Here is a screenshot of the dataframe
enter image description here

And here is what I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

print("df.at[5,'datetime']", df.at[5,"datetime"])
print("df.iloc['datetime', 5]", df.iloc[5]["datetime"])

Any idea, why I get this error and how to fix this problem?

>Solution :

It looks like datetime is your index column so you should be able to access it through df.index[5]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading