简体   繁体   English

具有不同dtype值的Pivos Pivot_table

[英]Pandas Pivot_table with different dtype values

I have a particularly strange behavior from pivot_table (or at least I think it is...) 我在pivot_table中有一个特别奇怪的行为(或者至少我认为是...)

I have got a dataframe extracted from database with dates that I use with pivot table to do some basics stats: 我从数据库中提取了一个dataframe ,其中包含与dataframe透视表一起使用以执行一些基本统计信息的日期:

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... 我可以在这些字段上使用数据透视表,但是如果我还将fied“ Cpt”添加到值(这是一个简单的int字段,其中包含1)以计算数据透视表分组了多少行,则只会显示Cpt字段,但不再是timedelta的...

Is it impossible to do the pivot table on different dtype ? 是否可以在不同的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. 您应该设置columns参数以指定要对values进行分组的组。

Do you have sample data? 你有样本数据吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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