简体   繁体   中英

Pandas Pivot_table with different dtype values

I have a particularly strange behavior from pivot_table (or at least I think it is...)

I have got a dataframe extracted from database with dates that I use with pivot table to do some basics stats:

pd.pivot_table(df,values["Diff_DGach_Dcent","Diff_DepCh_BoxPlt","Attente_totale"],
                    index=['id_chantier',"date_bl"], aggfunc=np.sum,fill_value=0)

I can pivot table on these fields but if I also add the fied "Cpt" to the values (it's a simple int field with 1 in it) to count how many lines are grouped by the pivot table , it'll only display the Cpt field but no more the timedelta ones...

Is it impossible to do the pivot table on different dtype ?

EDIT : Sample of Data to be processed

Diff_DGach_Dcent    Diff_DepCh_BoxPlt   Attente_totale  Cpt
    00:21:00    00:45:00    01:23:00    1
    00:26:00    00:18:00    02:16:00    1
    00:15:00    00:18:00    01:25:00    1
    00:25:00    00:18:00    01:25:00    1
    00:26:00    00:10:00    01:20:00    1
    00:20:00    00:14:00    01:38:00    1

You should set the columns parameter to specify the group that you want the values to be grouped on.

Do you have sample data?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM