1

I'm trying to get the index value of an element in the dataframe in pandas. I'm taking two values (date and price) from a database and putting in dataframe using pandas. I found how to find min and max value of price but for those values I want to know print out which date it is. I tried to use numpy where function but I couldn't figure it out. I'm noob sorry. Here is my code. Thank you..

import sqlite3
import pandas as pd
import numpy as np




conn = sqlite3.connect('price_daily.sqlite')
cur = conn.cursor()

tables_prices='''SELECT date, tryprice FROM Btc'''

df=pd.read_sql_query(tables_prices, conn)    #print(df.head())

x=df['tryprice'].max()

#I want to return date as string for this element in dataframe...

1 Answer 1

1

Use idxmax and idxmin

To get the entire row associated with the minimum tryprice

df.loc[df['tryprice'].idxmin()]

To get the Date column of the row associated with the minimum tryprice

df.at[df['tryprice'].idxmin(), 'date']
Sign up to request clarification or add additional context in comments.

1 Comment

@BitMagazin I'm glad it helped. Consider taking one of the actions laid out in this link => stackoverflow.com/help/someone-answers

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.