1

I would like to create a new column called "SUMIFS" in another dataframe entitled "Subset" (i.e. Subset['SUMIFS'] = ...), and I am wondering if it is possible to perform an excel like SUMIFS operation across dataframes in pandas. The criteria for the SUMIFS would be:

excel =SUMIFS(AT:AT,AS:AS,AS2,AQ:AQ,AQ2,AM:AM,AM2)

DateOfOutage    Tech    Sites   Duration Modified
8/3/2019    3G  CAI0012 2
8/2/2019    2G  CAI0012 3
8/3/2019    2G  CAI0012 0.1
8/3/2019    3G  CAI0012 0.1
8/2/2019    3G  CAI0019 3
8/2/2019    2G  CAI0019 115
8/2/2019    3G  CAI0019 112
8/3/2019    2G  CAI0024 178
8/3/2019    3G  CAI0024 175
8/2/2019    2G  CAI0024 34
8/2/2019    2G  CAI0024 449
8/2/2019    3G  CAI0024 442

data['Duration Modified'][(data['Sites']==data['Tech'] == data['DateOfOutage'])].sum()

DateOfOutage    Tech    Sites   Duration Modified   Sumifs
8/3/2019    3G  CAI0012 2   2.1
8/2/2019    2G  CAI0012 3   3
8/3/2019    2G  CAI0012 0.1 0.1
8/3/2019    3G  CAI0012 0.1 2.1
8/2/2019    3G  CAI0019 3   115
8/2/2019    2G  CAI0019 115 115
8/2/2019    3G  CAI0019 112 115
8/3/2019    2G  CAI0024 178 178
8/3/2019    3G  CAI0024 175 175
8/2/2019    2G  CAI0024 34  483
8/2/2019    2G  CAI0024 449 483
8/2/2019    3G  CAI0024 442 442
anky
  • 74,114
  • 11
  • 41
  • 70
bakr sayed
  • 11
  • 1
  • Use `data['Sumifs'] = data.groupby(['DateOfOutage', 'Tech','Sites']).transform('sum')` or `df['Sumifs'] = df.groupby(['DateOfOutage', 'Tech','Sites'])['Duration Modified'].transform('sum')` – Erfan Aug 26 '19 at 08:56
  • @Erfan - Sure, please add comemnts too. Thank you. – jezrael Aug 26 '19 at 08:57

0 Answers0