python大 pandas 数据框 - 无法弄清楚如何查找从df给出值的索引 [英] python pandas dataframe - can't figure out how to lookup an index given a value from a df

查看:575
本文介绍了python大 pandas 数据框 - 无法弄清楚如何查找从df给出值的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个数据数据数据。给定第二个df中的一个列的值,我想查找第一个df中的值的索引。更具体地说,我想创建一个第三个df,它只包含索引标签 - 使用第二个值从第一个查找其坐标。

  listso = [[21,101],[22,110],[25,113],[24,112],[21,109],[28,108],[30,102],[26,106],[25,111],[24,110]] 
data = pd.DataFrame(listso,index = list('abcdefghij'),columns = list('AB'))
rollmax = pd.DataFrame(data.rolling(center = False,window = 5 ).max())

所以对于第三个df,我希望使用 rollmax ,并找出他们在数据中显示的行。我们可以称之为第三个df indexlookup



例如, rollmax.ix [' j','A'] = 30 ,所以 indexlookup.ix ['j','A'] ='g' p>

谢谢!

解决方案

您可以使用其他索引编制系列方式:

  mapA = pd.Series(data.index,index = data.A)

然后 mapA [rollmax.ix ['j','A']] 'g'


I have 2 dataframes of numerical data. Given a value from one of the columns in the second df, I would like to look up the index for the value in the first df. More specifically, I would like to create a third df, which contains only index labels - using values from the second to look up its coordinates from the first.

listso = [[21,101],[22,110],[25,113],[24,112],[21,109],[28,108],[30,102],[26,106],[25,111],[24,110]]
data = pd.DataFrame(listso,index=list('abcdefghij'), columns=list('AB'))
rollmax = pd.DataFrame(data.rolling(center=False,window=5).max())

So for the third df, I hope to use the values from rollmax and figure out which row they showed up in data. We can call this third df indexlookup.

For example, rollmax.ix['j','A'] = 30, so indexlookup.ix['j','A'] = 'g'.

Thanks!

解决方案

You can build a Series with the indexing the other way around:

mapA = pd.Series(data.index, index=data.A)

Then mapA[rollmax.ix['j','A']] gives 'g'.

这篇关于python大 pandas 数据框 - 无法弄清楚如何查找从df给出值的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆