1

I have a pandas dataframe:

   Time(s)  RARb relative signal  Rescaled_CRABPII  atRA  RARa_tet  RARg_tet
0        0                     0          0.000000   100         0         0
1     7200                    20          0.000000   100         0         0
2    14400                    50         11.764706   100         0         0
3    21600                    90         58.823529   100         0         0
4    43200                   100        100.000000   100         0         0
5    50400                   100        105.882353   100         0         0
6    64800                   100        117.647059   100         0         0

How can I retrieve the value of RARb relative signal at df['Time(s)']==43200?

2 Answers 2

1

Let df be your dataframe, you can just:

a = df[df['Time(s)']==43200]['RARb relative signal']
Sign up to request clarification or add additional context in comments.

Comments

0

First, if you keep the df as is, you should use .iat[] or .at[] instead for scalar getting and setting (see examples on .iat[] and .at[] [here]1). So the .iat version (which is the faster of the two) would be:

val = df.iat[df['Time(s)']==43200, 1]

The column number is 1 because 'RARb relative signal' is the second column. If you're not sure what the column position will be you can either get that too with get_loc() or just use .at[] with label-based indexing:

val = df.at[df['Time(s)']==43200, 'RARb relative signal']

If you actually have a multiindex pass a tuple with all the multiindex levels instead of the single label.

Really though, why don't you make the time in seconds be the index? You could still use integer-based indexing to access items, and this approach seems to make much more sense for your data. First, reset the index:

df.index = df['Time(s)']

You may wish to then delete the 'Time(s)' column, that's up to you. Anyway with the new index you can just do:

val = df.at[43200, 'RARb relative signal'] 

If you're doing these sorts of value retrievals a lot, re-indexing and using .iat[] or .at[] can make a big performance difference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.