首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在其他数据熊猫蟒中从一个数据栏中查找相同的列?

如何在其他数据熊猫蟒中从一个数据栏中查找相同的列?
EN

Stack Overflow用户
提问于 2020-11-10 19:39:27
回答 1查看 80关注 0票数 0

我有一个这样的数据,

代码语言:javascript
复制
tabla_aciertos= {'Numeros_acertados' : [5,5,5,4,4,3,4,2,3,3,1,2,2],'Estrellas_acertadas': [2,1,0,2,1,2,0,2,1,0,2,1,0]}
categorias = [1,2,3,4,5,6,7,8,9,10,11,12,13]
categoria_de_premios = pd.DataFrame (tabla_aciertos,index = [categorias] )
categoria_de_premios
代码语言:javascript
复制
   Numeros_acertados  Estrellas_acertadas
1                   5                    2
2                   5                    1
3                   5                    0
4                   4                    2
5                   4                    1
6                   3                    2
7                   4                    0
8                   2                    2
9                   3                    1
10                  3                    0
11                  1                    2
12                  2                    1
13                  2                    0

另一个df:

代码语言:javascript
复制
sorteos_anteriores.iloc[:,:]

    uno dos tres    cuatro  cinco   Estrella1   Estrella2   bolas_Acertadas estrellas_Acertadas
Fecha                                   
2020-10-13  5   14  38  41  46  1   10  0   1
2020-09-10  11  15  35  41  50  5   8   1   0
2020-06-10  4   21  36  41  47  9   11  0   0
2020-02-10  6   12  15  40  45  3   9   0   0
2020-09-29  4   14  16  41  44  11  12  0   1
... ... ... ... ... ... ... ... ... ...
2004-12-03  15  24  28  44  47  4   5   0   0
2004-05-03  4   7   33  37  39  1   5   0   1
2004-02-27  14  18  19  31  37  4   5   0   0
2004-02-20  7   13  39  47  50  2   5   1   0
2004-02-13  16  29  32  36  41  7   9   0   0
1363 rows × 9 columns

现在,我需要在df的每一行中看到"sorteos_anteriores“是在第一个df的所有行之一,"tabla_aciertos”。

让我举个例子,

Inmagine在"sorteos_anteriores“中有:2019-11-2 in the column "bolas_Acertadas"= 5 and "estrellas_Acertadas= 1"。现在你走到第一桌,"tabla_aciertos“,你可以在(index 2 = "Numeros_acertados" = 5 and Estrellas_acertadas=1)中找到它。你获得了第二个(index=2)班级奖。您应该在"sorteos_anteriores“中创建一个新的列”from 1 to 13“,如果您没有得到0 or Nan的某种奖励,则在每一行中写一个数字from 1 to 13

我试过:

代码语言:javascript
复制
sorteos_anteriores ['categorias']  = sorteos_anteriores(sorteos_anteriores.loc[:,'bolas_Acertadas':'estrellas_Acertadas'] == tabla_premios.iloc[ : ,0:2])

也适用于where和合并,但没有任何效果。

谢谢你的帮助。

,多亏了Cuina,我能做到。

回答这里

EN

回答 1

Stack Overflow用户

发布于 2020-11-10 20:22:56

代码语言:javascript
复制
# supposing that the indexes, starting from one, correspond to the the premiums
categoria_de_premios['Categoria'] = df.index

# Merge using pd.merge and the appropriate arguments
sorteos_anteriores = (sorteos_anteriores.merge(
    categoria_de_premios,
    how='outer',
    left_on=['bolas_Acertadas','estrellas_Acertadas'],
    right_on=['Numeros_acertados', 'Estrellas_acertadas']
)).drop(columns=['Numeros_acertados', 'Estrellas_acertadas'])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64775678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档