Python Forum
very simple dataframe question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: very simple dataframe question (/thread-7276.html)



very simple dataframe question - really_this_dumb - Jan-02-2018

Hi all,

New to python but am coding a project to become more familiar.

My dilemma is this: how do I access data within a given slice of a dataframe, which, to my understanding, is itself a dataframe, if I know that data's index?

For example:

d = pandas.DataFrame(columns = ['first', 'second', 'third'], dtype=float)

# insert code that instantiates the columns with float values
# for brevity's sake, let's also presume that d has multiple rows
# and that I know the value of one of the columns in the row I am trying to access

r = d.loc[d['first'] == some_value] # <-- this seems to work to give me the row I need

requiredValue = r[2]  # <-- this is not working, and is returning 'None' for requiredValue


Is there something obvious I am missing?

I have been working on this and can't seem to suss out the required result.

I do know that requiredValue, in my code, is a DataFrame, and I can access its columnar descriptors, but, again, when I use either r.loc[2] or r[2], I get None as the data's value.

I've been all over StackExchange and have read through a few different docs, and they all seem to point to the code I wrote as being right.

Huh