Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取数据帧的索引值_Python_Pandas - Fatal编程技术网

Python 获取数据帧的索引值

Python 获取数据帧的索引值,python,pandas,Python,Pandas,我试图在pandas中获取dataframe中元素的索引值。我从数据库中获取两个值(日期和价格),并使用pandas将其放入数据框中。我找到了如何找到价格的最小值和最大值,但对于这些值,我想知道打印出来的日期。我尝试使用numpy where函数,但我想不出来。对不起。这是我的密码。谢谢 import sqlite3 import pandas as pd import numpy as np conn = sqlite3.connect('price_daily.sqlite') cu

我试图在pandas中获取dataframe中元素的索引值。我从数据库中获取两个值(日期和价格),并使用pandas将其放入数据框中。我找到了如何找到价格的最小值和最大值,但对于这些值,我想知道打印出来的日期。我尝试使用numpy where函数,但我想不出来。对不起。这是我的密码。谢谢

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...

使用
idxmax
idxmin

要获取与最小值
tryprice

df.loc[df['tryprice'].idxmin()]
df.at[df['tryprice'].idxmin(), 'date']
要获取与最小
胰米相关联的行的
日期

df.loc[df['tryprice'].idxmin()]
df.at[df['tryprice'].idxmin(), 'date']

@我很高兴它起到了作用。考虑在这个链接中列出的一个动作