如何从多个数据帧中选择数据

时间:2016-02-04 15:16:45

标签: numpy pandas

我是熊猫的初学者,我必须首先调用数据帧 DATA_DF包含许多字段,我对DATA_DF['Date effet']感兴趣的类型为datetime 我有其他数据框称为TAUX_DF,包含年份,每年都有一个值

TAUX_DF =
Année   <10 ans >10 ans
1987    2,8168% 3,4664%
1988    2,8168% 3,4664%
1989    2,8168% 3,4664%
1990    2,8168% 3,4664%

我想在DATA_DF上创建一个名为&#34; DATA_DF [&#39; Taux technique&#39;]&#34; 从DATA_DF['Date effet'].dt.year开始将其与TAUX_DF['Année']上的年份进行比较,并将这样的值放在Excel上

=SI(G5>120;RECHERCHEV(ANNEE(C5);Taux!$A$2:$C$29;3;FAUX);RECHERCHEV(ANNEE(C5);Taux!$A$2:$C$29;2;FAUX))

1 个答案:

答案 0 :(得分:0)

DATA_DF['Année'] = DATA_DF['Date effet'].dt.year ## ==> make column with year of the data_df in order to compare (merge) it later on with the 'TAUX_DF'.

DATA_DF = pd.merge(DATA_DF,TAUX_DF,left_on='Année',right_on='Année', how='left')