Q:

Create a dataframe based on an old one

I have a dataframe as :
   A   B   C   D
   0   s   3   a
   4   s   2   a
   5   s   2   a
   6   s   1   a
   7   s   2   b
   7   s   3   b
   6   s   0   b

How can I create a new dataframe as the following? 
   A   B   C   D
   0   4   8   4-a
   7   3   5   3-b

The new dataframe summarize the old one by grouped the elements of column "D", So "A" is the index, "B" is count of elements, "C" is sum of element where "D" has the same value. 

A:

Well, assuming that your data is stored in df,  it's a multistep process which could be done like this
import pandas as pd

data = {'A': {0: 0, 1: 4, 2: 5, 3: 6, 4: 7, 5: 7, 6: 6},
        'B': {0: 's', 1: 's', 2: 's', 3: 's', 4: 's', 5: 's', 6: 's'},
        'C': {0: 3, 1: 2, 2: 2, 3: 1, 4: 2, 5: 3, 6: 0},
        'D': {0: 'a', 1: 'a', 2: 'a', 3: 'a', 4: 'b', 5: 'b', 6: 'b'}}
df = pd. DataFrame(data)

# Handling column A (first index per value in D)
output_df = df.drop_duplicates(subset='D', keep='first')

# Itering through rows
for index, row in output_df.iterrows():

    #Calcultating the counts in B
    output_df.loc[index, 'B'] = df[df. D == row. D].B.count()

    #Calcultating the sum in C
    output_df.loc[index, 'C'] = df[df. D == row. D].C.sum()

#Finally changing values in D by concatenating values in B and D
output_df.loc[:, 'D'] = output_df. B.map(str) + "-" +  output_df. D

Output : 

   A   B   C   D
   0   4   8   4-a
   7   3   5   3-b

