Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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 如何正确获取pandas中的单个单元格:loc[index,column]VS get_value(index,column)_Python_Pandas_Dataframe - Fatal编程技术网

Python 如何正确获取pandas中的单个单元格:loc[index,column]VS get_value(index,column)

Python 如何正确获取pandas中的单个单元格:loc[index,column]VS get_value(index,column),python,pandas,dataframe,Python,Pandas,Dataframe,使用哪种方法(在性能和可靠性方面)更好地从pandas数据帧获取单个单元格:get_value()或loc[]?您最终可以在以下内容中找到信息: 用于显式获取值(相当于不推荐的df.get_值('a','a')) 但如果使用它,则没有警告 但如果检查: 从一维数组快速查找值仅当您知道自己在做什么时才使用此选项 所以我认为更好的是使用 计时: df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6],

使用哪种方法(在性能和可靠性方面)更好地从pandas
数据帧获取单个单元格:get_value()或loc[]?

您最终可以在以下内容中找到信息:

用于显式获取值(相当于不推荐的df.get_值('a','a'))

但如果使用它,则没有警告

但如果检查:

从一维数组快速查找值仅当您知道自己在做什么时才使用此选项

所以我认为更好的是使用

计时

df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9],
                   'D':[1,3,5],
                   'E':[5,3,6],
                   'F':[7,4,3]})

print (df)

In [93]: %timeit (df.loc[0, 'A'])
The slowest run took 6.40 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 177 µs per loop

In [96]: %timeit (df.at[0, 'A'])
The slowest run took 17.01 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 7.61 µs per loop

In [94]: %timeit (df.get_value(0, 'A'))
The slowest run took 23.49 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 3.36 µs per loop

get\u value()
-将更快更合适我不理解文档中关于
弃用get\u value()
的这句话。。。熊猫本身在内部使用
get_value()
查看iat/iloc、at/loc和ix之间的差异请参见@JulienMarrec-谢谢。我还发现
df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9],
                   'D':[1,3,5],
                   'E':[5,3,6],
                   'F':[7,4,3]})

print (df)

In [93]: %timeit (df.loc[0, 'A'])
The slowest run took 6.40 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 177 µs per loop

In [96]: %timeit (df.at[0, 'A'])
The slowest run took 17.01 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 7.61 µs per loop

In [94]: %timeit (df.get_value(0, 'A'))
The slowest run took 23.49 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 3.36 µs per loop