Q:

New dataframe: group by date, condition on time, sum values with if condition

I am trying to find a "pandas" solution for this:
I have a dataframe with two columns, one for datetime and one for numeric values. 
Assume this for the dataframe:
datarange=pd.date_range('01-05-2018 13:00:00', periods=12000, freq="1H")
range_series=pd. Series(np.random.randint(-2,2,size=12000).astype(float), index=datarange)
frame=pd. DataFrame(range_series, columns=['diffs'])
frame.index.name='datetime'

The output is something like this:
print(frame.head(10), frame.tail(10))

           datetime    diffs
2018-01-05 13:00:00   -2.0
2018-01-05 14:00:00    0.0
2018-01-05 15:00:00   -2.0
2018-01-05 16:00:00    1.0
2018-01-05 17:00:00    1.0
2018-01-05 18:00:00    1.0
2018-01-05 19:00:00   -1.0
2018-01-05 20:00:00   -2.0
2018-01-05 21:00:00   -2.0
2018-01-05 22:00:00   -2.0
Freq: H, dtype: float64
           datetime    diffs
2019-05-20 03:00:00   -1.0
2019-05-20 04:00:00   -1.0
2019-05-20 05:00:00    0.0
2019-05-20 06:00:00    1.0
2019-05-20 07:00:00    0.0
2019-05-20 08:00:00   -2.0
2019-05-20 09:00:00    1.0
2019-05-20 10:00:00   -1.0
2019-05-20 11:00:00    1.0
2019-05-20 12:00:00   -2.0
Freq: H, dtype: float64

I need to create a new dataframe with new columns:
new column A: sum of diffs for the same date from hour 5:00 to hour 21:00 if diffs.value>0
new column B: sum of diffs for the same date from hour 5:00 to hour 21:00 if diffs.value<0
new column C: sum of diffs if diffs.value>0 for the group 'y-m-d 22:00:00' to 'y-m-d+1 4:00:00' 
new column D: sum of diffs if diffs.value<0 for the group 'y-m-d 22:00:00' to 'y-m-d+1 4:00:00'
So practically, 5 new columns:
1) date
2) to accommodate the sum of the positive diffs per day from hours 5 to 21
3) to accommodate the sum of the negative diffs per day from hours 5 to 21
4) to accommodate the sum of the positive diffs from 22:00 of one day to 4:00 of the next day
5) to accommodate the sum of the negative diffs from 22:00 of one day to 4:00 of the next day
I could start iterating over lists to create new lists and then bring them back together into a new dataframe.  But I am trying to figure out if I could somehow groupby and apply criteria in different columns and aggregate. 
Note: the sum as described in (4) and (5) should fall under the date of the day 1. 
I would welcome your input.  I am not a developer and definitely not experienced in pandas, but the library seems to offer huge possibilities, that I try to explore. 
Hoping my description is clear, thanks in advance. 

A:

Did it myself after all... and I post my code, but would welcome anyone with a cleaner, shorter and more elegant code. 
Starting with this dataframe
dates=pd.date_range('01-05-2018 13:00:00', periods=12000, freq="1H")
range_series=pd. Series(np.random.randint(-2,2,size=12000).astype(float), index=dates)
df=pd. DataFrame(range_series, columns=['diffs'])
df.index.name='datetime'

I create a date and a time column:
df['date']=df.index.date
df['time']=df.index.time

I locate the new columns to the front (so that I am able to control my calculations):
new_df = df.iloc[:, np.r_[1,2,0]]

I create two different dataframes slicing the times I want each time:
day_df=new_df.between_time('05:00', '21:00')
night_df=new_df.between_time('22:00','04:00')

I groupby 'date' and I aggregate three methods (sum, sum if positive, sum if negative):
day_change=day_df.groupby(day_df['date'])['diffs'].\
        agg([('daytime change' , lambda x : x.sum()) ,\
             ('daytime negative change' , lambda x : x[x < 0].sum()) , \
             ('daytime positive change' , lambda x : x[x > 0].sum())])
night_change=night_df.groupby(night_df['date'])['diffs'].\
        agg([('nighttime change' , lambda x : x.sum()) ,\
             ('nighttime negative change' , lambda x : x[x < 0].sum()) , \
             ('nighttime positive change' , lambda x : x[x > 0].sum())])

I concatenate by the horizontal axis the two dataframes with an "inner join" just in case the number of rows of the two dataframes are not equal:
change=pd.concat([day_change,night_change], axis=1, join='inner')

And I get the desired output:
print(change.head(1))
            daytime change  daytime negative change  daytime positive change  \
date                                                                           
2018-01-05            -7.0                    -10.0                      3.0   

            nighttime change  nighttime negative change  \
date                                                      
2018-01-05               0.0                        0.0   

            nighttime positive change  
date                                   
2018-01-05                        0.0  

