1

have a data frame:

   A    B    C   
0  ax   No   1
1  dr   No   7
2  tx   Yes  3
3  ht   Yes  4
4  uj   No   1
5  uz   No   2
6  ax   No   3
7  uj   Yes  4
8  uj   No   1

In a second DataFrame I have only one entrie for each unique value in column A (from df1) and would like to add the sum of all values from column C with the corresponding value for column A and also the average.

   A    Sum     Avr   
0  ax   4       2 
1  dr   7       7 
2  ht   4       4
3  tx   3       3
4  uj   6       2
5  uz   2       2 

Is it possible to do this without:

for row in df.iterrows():
  • similar question: https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum – albert Nov 27 '20 at 15:58
  • yes and no, with this solution I get a new dataframe but does this also work if df2 already exists? –  Nov 27 '20 at 17:32
  • I used groupby with .values to get the results, but they r not sorted, so I add sort_index but it seems that I can't combine this with .values. –  Nov 28 '20 at 16:52
  • Also for the value_count the sort_index will not work. :/ So I get results, but they r not related to the value of column A –  Nov 28 '20 at 16:53

0 Answers0