0

Hey stack family need some help in getting a value from a pandas dataframe but got stuck up here any help would be appreciated.

I want to get a value from this ohlc dataframe.

brick_counts  time_id  efi
   1             1     1000
   2             1     1500
   3             1     2000
   4             2     2500 
   5             2     2600
   6             2     3200 
 

And here to slice a single value from the efi column first i'm making brick and time_id column as the index and trying this to get the value.

I'm taking the max of the time_id because i need the highest time_id from the dataframe.

ohlc.set_index(['brick_counts' , 'time_id'] , inplace = True)
latest_time = ohlc['time_id'].max()

efi_pos1 = ohlc.loc[(6,int(latest_time)),'efi']

But the issue is it gives me the value in series format having index set in place of giving only a single float number which i need.

Can anyone please prefer me any other slicing method to get the value without applying brick_counts and time_id as index ?

I need the value of efi where brick is equals to 6 and time_id is the highest in the dataframe.

2 Answers2

0

getting the first efi for the max time_id

df.loc[df['time_id'].idxmax(), 'efi']

output: 2500

getting the max efi for the max time_id

df.loc[df['time_id'].eq(df['time_id'].max()), 'efi'].max()

output: 3200

mozway
  • 194,879
  • 13
  • 39
  • 75
  • hey @mozway i need the value according to brick_counts and time_id combined. – basudev patro Nov 19 '21 at 09:23
  • @basudevpatro the logic is not clear to me, you want a max value, which max? please clarify in your question: which number do you want and why? – mozway Nov 19 '21 at 09:26
0
efi_pos1 = ohlc.loc[(ohlc['brick_counts'] == 6) & (ohlc['time_id'] == ohlc['time_id'].max()), 'efi'].values[0]

print(efi_pos1)

Output:

3200
Wilian
  • 1,247
  • 4
  • 11