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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple question (I guess) tchadrack 1 1,317 Jan-08-2022, 06:36 AM
Last Post: buran
  Simple pandas question mcva 4 2,646 Dec-17-2021, 04:47 PM
Last Post: mcva
  Python & Dataframe basic question georgialtr 0 3,860 Apr-06-2020, 03:59 PM
Last Post: georgialtr
  Simple String to Time within a pandas dataframe Ecniv 1 2,508 Jun-14-2019, 03:25 AM
Last Post: scidam
  Simple pandas dataframe question popohoma 1 3,540 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  Newbie question to return only the index of a dataframe zydjohn 0 2,554 Jan-22-2018, 03:40 PM
Last Post: zydjohn
  Question for dataframe to replace INF value zydjohn 0 5,142 Jan-15-2018, 10:00 PM
Last Post: zydjohn
  Newbie question: how to generate dataframe and use multiple regression zydjohn 0 2,279 Dec-10-2017, 09:49 AM
Last Post: zydjohn
  pd.DataFrame question smw10c 2 4,000 Mar-30-2017, 09:12 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020