Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 very simple dataframe question
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.


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python & Dataframe basic question georgialtr 0 623 Apr-06-2020, 03:59 PM
Last Post: georgialtr
  Simple String to Time within a pandas dataframe Ecniv 1 835 Jun-14-2019, 03:25 AM
Last Post: scidam
  Simple pandas dataframe question popohoma 1 919 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  Newbie question to return only the index of a dataframe zydjohn 0 966 Jan-22-2018, 03:40 PM
Last Post: zydjohn
  Question for dataframe to replace INF value zydjohn 0 3,598 Jan-15-2018, 10:00 PM
Last Post: zydjohn
  Newbie question: how to generate dataframe and use multiple regression zydjohn 0 931 Dec-10-2017, 09:49 AM
Last Post: zydjohn
  pd.DataFrame question smw10c 2 2,160 Mar-30-2017, 09:12 PM
Last Post: smw10c

Forum Jump:

Users browsing this thread: 1 Guest(s)