Ptyhon-与TimeSeries比较两个数据帧并获得总和

时间:2020-07-29 12:42:14

标签: python pandas dataframe sumifs

我有2个带有日期列的 dataframes

问题陈述:在第二个数据帧(df1)中,我想查看条件匹配的值,如下所示-

键,说明值应该匹配,并获得日期短的“值”的总和。

下面的示例-

enter image description here

import pandas as pd
import numpy as np

data = {'Key':['1a','2b','3c','4d','1a','2b','3c','4d'], 'Description': ['x','y','z',np.nan,'x',np.nan,'z','u'],
        'col3':['A','B','C','A','A','B','Y','D'],
        'Date': ['1/1/2020','2/1/2020','8/1/2019','4/1/2020','5/1/2020','6/1/2020',np.nan,'5/1/2020'],
        'values':[1,3,5,7,7,9,3,6]}
df = pd.DataFrame(data)
df


data1 = {'Key':['1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a','1a'],
        'Description': ['x','x','x','x','x','x','x','x','y','y','y','y','y','y','y','y'],
        'Date': ['1/1/2020','2/1/2020','3/1/2019','4/1/2020','5/1/2020','6/1/2020','7/1/2020','8/1/2020','1/1/2020','2/1/2020','3/1/2019','4/1/2020','5/1/2020','6/1/2020','7/1/2020','8/1/2020']}
df1 = pd.DataFrame(data1)
df1

0 个答案:

没有答案