将行和列总计添加到数据透视表失败

时间:2019-01-10 20:43:00

标签: python pandas rowsum column-sum

我想显示行和列的总计。我使用margin = True,但输出未显示行总数,如下代码和输出:

import pandas as pd
df2 = pd.read_csv("https://www.dropbox.com/s/90y07129zn351z9/test_data.csv?dl=1",encoding="latin-1")

df2['received'] = pd.to_datetime(df2['received'])
df2['sent'] = pd.to_datetime(df2['sent'])


pvt_all = df2.dropna(axis=0, how='all', subset=['received', 'sent'])\
    .pivot_table(index=['site'], values=['received','sent'],\
    aggfunc='count', margins=True, dropna=False)
pvt_all['to_send']= pvt_all['received']-pvt_all['sent'] 
pvt_all=pvt_all[['received','sent','to_send']] 
pvt_all

received    sent    to_send
site            
2   32.0    27.0    5.0
3   20.0    17.0    3.0
4   33.0    31.0    2.0
5   40.0    31.0    9.0
All 125.0   106.0   19.0

下面的数据样本虽然很长,但仍可以为您提供便利。您还可以在上面的df矢量中提供的url中找到。 DataFrame由四个变量组成:日期,地点,接收和发送。

date    site    received    sent
7/10/2018   2       
7/10/2018   2       
7/11/2018   2       
7/11/2018   2       
7/11/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/13/2018   2   7/13/2018 12:50 7/18/2018 14:44
7/13/2018   2       
7/18/2018   2       
7/19/2018   2       
7/19/2018   2       
7/23/2018   2       
7/23/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/13/2018   2       
7/13/2018   2       
7/13/2018   2       
7/16/2018   2       
7/16/2018   2       
7/17/2018   2       
7/17/2018   2       
7/18/2018   2       
7/18/2018   2       
7/18/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/19/2018   2       
7/19/2018   2       
7/19/2018   2       
7/26/2018   2       
7/26/2018   2       
7/25/2018   2       
7/24/2018   2       
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/24/2018   2       
7/23/2018   2       
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/24/2018   2       
7/24/2018   2       
7/24/2018   2       
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/23/2018   2       
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/24/2018   2       
7/9/2018    2       
7/10/2018   2       
7/9/2018    2   7/9/2018 15:19  7/11/2018 10:25
7/10/2018   2   7/10/2018 12:26 7/11/2018 10:25
7/10/2018   2       
7/19/2018   2       
7/19/2018   2       
7/19/2018   2   7/19/2018 14:22 7/25/2018 10:35
7/23/2018   2       
7/23/2018   2   7/23/2018 15:53 7/25/2018 10:35
7/23/2018   2       
7/19/2018   2       
7/19/2018   5       
7/23/2018   2       
7/23/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/6/2018    2       
7/6/2018    2       
7/6/2018    2       
7/9/2018    2       
7/9/2018    2       
7/24/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/2/2018    2       
7/2/2018    2       
7/3/2018    2       
7/3/2018    2       
7/3/2018    2       
6/29/2018   2       
6/29/2018   2       
6/29/2018   2       
7/2/2018    2       
7/2/2018    2       
7/11/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/9/2018    2       
7/9/2018    2       
7/9/2018    2       
7/10/2018   2   7/10/2018 12:26 7/11/2018 10:25
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/11/2018   2   7/11/2018 14:54 7/18/2018 14:44
7/11/2018   2       
7/13/2018   2       
7/12/2018   2       
7/13/2018   2       
7/13/2018   2       
7/13/2018   2       
7/13/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/18/2018   2   7/18/2018 14:35 7/25/2018 10:35
7/19/2018   2       
7/18/2018   2       
7/19/2018   2       
7/19/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/18/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2   7/26/2018 15:35 
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/23/2018   2       
7/24/2018   2       
7/24/2018   2       
7/24/2018   2   7/24/2018 15:31 7/25/2018 10:35
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2   7/25/2018 15:34 
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/26/2018   2       
7/26/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/26/2018   2   7/26/2018 15:55 
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/27/2018   2       
7/24/2018   2       
7/24/2018   2       
7/24/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
6/29/2018   2       
6/29/2018   2       
7/2/2018    2       
7/2/2018    2       
7/2/2018    2       
6/29/2018   2       
7/6/2018    2       
7/6/2018    2       
7/6/2018    2       
7/9/2018    2       
7/2/2018    2       
7/3/2018    2       
7/3/2018    2       
7/3/2018    2       
7/3/2018    2       
7/3/2018    2       
7/3/2018    2   7/3/2018 15:20  7/4/2018 11:35
7/4/2018    2       
7/5/2018    2       
7/6/2018    2       
7/4/2018    2       
7/25/2018   2       
7/25/2018   2       
7/25/2018   2       
7/26/2018   2       
7/5/2018    2   7/5/2018 15:15  7/11/2018 10:25
7/6/2018    2       
7/9/2018    2   7/9/2018 15:19  7/11/2018 10:25
7/9/2018    2       
7/10/2018   2       
7/5/2018    2   7/5/2018 15:15  7/11/2018 10:25
7/6/2018    2       
7/6/2018    2   7/6/2018 13:30  7/11/2018 10:25
7/6/2018    2       
7/6/2018    2   7/6/2018 13:30  7/11/2018 10:25
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/11/2018   2       
7/10/2018   2       
7/13/2018   2       
7/13/2018   2   7/13/2018 12:50 
7/13/2018   2   7/13/2018 12:50 7/18/2018 14:44
7/12/2018   2   7/12/2018 15:30 7/18/2018 14:44
7/11/2018   2       
7/11/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/27/2018   2       
7/27/2018   2       
7/26/2018   2       
7/26/2018   2   7/26/2018 15:55 
7/26/2018   2       
7/26/2018   2       
7/27/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/16/2018   2       
7/19/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/17/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
7/26/2018   2       
6/29/2018   2       
7/2/2018    2       
7/2/2018    2       
7/2/2018    2       
7/2/2018    2       
7/2/2018    2       
7/6/2018    2       
7/6/2018    2       
7/9/2018    2       
7/9/2018    2       
7/2/2018    2   7/2/2018 15:38  7/4/2018 11:35
7/2/2018    2       
7/3/2018    2       
7/5/2018    2       
7/3/2018    2   7/3/2018 14:15  7/4/2018 11:35
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/10/2018   2       
7/11/2018   2       
7/11/2018   2       
7/11/2018   2       
7/12/2018   2       
7/12/2018   2       
7/12/2018   2       
7/13/2018   2       
7/13/2018   2       
7/13/2018   2       
7/16/2018   2   7/16/2018 14:25 7/4/2018 15:30
7/16/2018   2       
7/16/2018   2       
7/17/2018   2   7/17/2018 14:50 7/18/2018 14:44
7/17/2018   2       
7/17/2018   2       
7/18/2018   2       
7/17/2018   2       
7/18/2018   2       
7/18/2018   2   7/18/2018 14:35 7/25/2018 10:35
7/27/2018   2       
7/27/2018   2       
7/27/2018   2       
7/27/2018   2       
7/27/2018   2       
7/27/2018   2       
7/27/2018   2       
6/20/2018   5       
6/20/2018   5       
6/22/2018   5       
6/19/2018   5   6/19/2018 14:20 6/28/2018 14:20
6/19/2018   5   6/19/2018 14:20 6/28/2018 14:20
6/27/2018   5       
6/28/2018   5       
6/28/2018   5   6/28/2018 11:30 7/4/2018 15:30
6/28/2018   5       
6/28/2018   5       
7/24/2018   5       
7/24/2018   5       
6/28/2018   5       
7/2/2018    5       
7/2/2018    5       
7/2/2018    5       
7/2/2018    5       
6/19/2018   5       
6/20/2018   5   6/19/2018 14:20 6/28/2018 14:20
6/20/2018   5       
6/19/2018   5       
6/19/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
6/26/2018   5   6/26/2018 11:40 6/28/2018 14:20
6/27/2018   5       
6/27/2018   5   6/27/2018 14:36 6/28/2018 14:20
6/27/2018   5       
6/19/2018   5       
6/19/2018   5       
6/19/2018   5       
6/22/2018   5       
6/20/2018   5   6/19/2018 12:40 6/28/2018 14:20
6/20/2018   5       
6/20/2018   5       
6/20/2018   5   6/20/2018 11:10 6/28/2018 14:20
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5   6/21/2018 1:26  6/28/2018 14:20
6/22/2018   5       
6/22/2018   5       
6/22/2018   5       
6/22/2018   5   6/22/2018 2:30  6/28/2018 14:20
6/26/2018   5       
6/26/2018   5       
6/26/2018   5   6/20/2018 11:10 6/28/2018 14:20
6/26/2018   5   6/26/2018 2:36  6/28/2018 14:20
6/26/2018   5       
6/26/2018   5       
6/26/2018   5       
6/27/2018   5   6/27/2018 14:36 6/28/2018 14:20
6/27/2018   5       
6/27/2018   5       
6/28/2018   5       
6/28/2018   5       
6/28/2018   5       
6/28/2018   5       
6/28/2018   5       
6/19/2018   5       
6/19/2018   5       
6/19/2018   5       
6/19/2018   5       
6/19/2018   5   6/19/2018 2:20  6/28/2018 14:20
6/20/2018   5   6/20/2018 2:15  6/28/2018 14:20
6/20/2018   5       
6/20/2018   5       
6/20/2018   5       
6/22/2018   5       
6/22/2018   5       
6/22/2018   5       
6/22/2018   5       
6/22/2018   5       
7/25/2018   5       
7/25/2018   5       
7/25/2018   5   7/25/2018 14:45 
7/25/2018   5       
7/25/2018   5       
7/24/2018   5       
7/24/2018   5       
7/25/2018   5   7/25/2018 14:45 
7/25/2018   5       
7/25/2018   5       
7/25/2018   5       
7/25/2018   5       
7/25/2018   5       
7/25/2018   5       
6/22/2018   5   6/22/2018 12:00 6/28/2018 14:20
6/20/2018   5   6/21/2018 2:35  6/28/2018 14:20
6/20/2018   5       
6/20/2018   5       
6/20/2018   5       
6/26/2018   5       
6/26/2018   5       
6/26/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/22/2018   5       
6/22/2018   5   6/22/2018 14:30 6/28/2018 14:20
6/22/2018   5       
6/22/2018   5       
6/26/2018   5       
6/26/2018   5       
6/26/2018   5       
6/26/2018   5       
6/26/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
6/21/2018   5       
7/3/2018    5       
7/3/2018    5       
7/3/2018    5       
7/3/2018    5       
7/3/2018    5   7/3/2018 14:45  7/4/2018 15:30
7/2/2018    5       
7/2/2018    5       
7/2/2018    5       
7/2/2018    5       
7/2/2018    5       
7/24/2018   5       
7/24/2018   5       
7/25/2018   5       
7/24/2018   5       
7/24/2018   5       
7/24/2018   5       
7/25/2018   5       
7/24/2018   5   7/25/2018 14:45 
7/24/2018   5       
7/24/2018   5       
7/23/2018   5       
7/24/2018   5       
7/24/2018   5       
7/3/2018    5       
7/3/2018    5   7/3/2018 14:45  7/4/2018 15:30
7/3/2018    5       
7/23/2018   5       
7/3/2018    5       
7/3/2018    5   7/3/2018 14:45  7/4/2018 15:30
7/3/2018    5       
7/3/2018    5       
7/11/2018   5       
7/10/2018   5       
7/11/2018   5   7/11/2018 12:47 7/13/2018 15:30
7/11/2018   5       
7/11/2018   5       
7/24/2018   5       
7/23/2018   5       
7/24/2018   5       
7/24/2018   5       
7/23/2018   5       
7/24/2018   5   7/24/2018 13:40 
7/23/2018   5       
7/24/2018   5       
7/24/2018   5       
7/23/2018   5       
7/24/2018   5       
7/23/2018   5   7/23/2018 16:20 
7/23/2018   5       
7/24/2018   5       
7/24/2018   5       
7/23/2018   5       
7/23/2018   5       
7/23/2018   5       
7/24/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5   7/10/2018 16:10 7/13/2018 15:30
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/16/2018   5       
7/10/2018   5   7/10/2018 16:20 7/13/2018 15:30
7/10/2018   5       
7/10/2018   5       
7/10/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/18/2018   5       
7/18/2018   5   7/18/2018 12:35 7/21/2018 11:20
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/11/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/12/2018   5       
7/12/2018   5       
7/12/2018   5   7/12/2018 16:38 7/13/2018 15:30
7/12/2018   5       
7/12/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/20/2018   5       
7/23/2018   5       
7/23/2018   5       
7/16/2018   5       
7/23/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/20/2018   5       
7/20/2018   5       
7/20/2018   5       
7/20/2018   5       
7/18/2018   5       
7/23/2018   5       
7/23/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/20/2018   5       
7/20/2018   5       
7/20/2018   5       
7/20/2018   5       
7/23/2018   5       
7/23/2018   5       
7/23/2018   5       
7/23/2018   5       
7/23/2018   5       
7/24/2018   5       
7/24/2018   5       
7/24/2018   5       
7/20/2018   5       
7/20/2018   5       
7/20/2018   5       
7/18/2018   5       
7/24/2018   5       
7/18/2018   5       
7/18/2018   5   7/18/2018 13:00 7/21/2018 11:20
7/18/2018   5   7/18/2018 10:30 7/21/2018 11:20
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/16/2018   5       
7/16/2018   5       
7/19/2018   5       
7/20/2018   5       
7/20/2018   5   7/20/2018 14:30 7/21/2018 11:20
7/20/2018   5       
7/20/2018   5       
7/19/2018   5       
7/16/2018   5       
7/16/2018   5       
7/16/2018   5       
7/16/2018   5       
7/16/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5   7/19/2018 11:50 7/21/2018 11:20
7/19/2018   5       
7/19/2018   5       
7/23/2018   5       
7/23/2018   5   7/23/2018 16:20 
7/23/2018   5       
7/13/2018   5       
7/25/2018   5       
7/25/2018   5   7/25/2018 14:45 
7/25/2018   5   7/25/2018 14:45 
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/19/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/13/2018   5       
7/18/2018   5       
7/18/2018   5       
7/18/2018   5       
7/23/2018   5   7/23/2018 16:20 
7/19/2018   5       
7/19/2018   5   7/19/2018 13:30 7/21/2018 11:20
7/19/2018   5       
7/19/2018   5       
7/20/2018   5       
6/26/2018   4       
6/26/2018   4       
6/27/2018   4       
6/27/2018   4       
6/27/2018   4       
6/26/2018   4       
6/27/2018   4       
6/27/2018   4       
6/27/2018   4       
6/27/2018   4       
7/3/2018    4       
6/28/2018   4       
6/28/2018   4       
7/3/2018    4       
7/4/2018    4       
6/28/2018   4       
6/29/2018   4       
6/28/2018   4       
6/28/2018   4       
6/29/2018   4       
6/28/2018   4       
6/28/2018   4   6/28/2018 15:00 7/4/2018 15:45
6/28/2018   4       
6/28/2018   4       
6/29/2018   4       
7/11/2018   4       
7/11/2018   4       
7/6/2018    4       
7/6/2018    4       
7/6/2018    4       
7/11/2018   4       
7/11/2018   4       
7/11/2018   4       
7/11/2018   4       
7/11/2018   4       
7/12/2018   4       
7/12/2018   4   7/12/2018 14:09 7/17/2018 15:00
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/13/2018   4       
7/13/2018   4       
7/13/2018   4       
7/13/2018   4   7/13/2018 10:52 7/17/2018 15:00
7/13/2018   4       
7/12/2018   4   7/12/2018 16:28 7/17/2018 15:00
7/13/2018   4   7/13/2018 10:52 7/17/2018 15:00
7/13/2018   4       
7/13/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/13/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4   7/18/2018 16:21 7/24/2018 14:30
7/19/2018   4       
7/16/2018   4       
7/13/2018   4       
7/13/2018   4       
7/13/2018   4       
7/16/2018   4       
7/17/2018   4       
7/13/2018   4       
7/16/2018   4       
7/16/2018   4       
7/13/2018   4   7/13/2018 14:15 7/17/2018 15:00
7/12/2018   4       
7/11/2018   4       
7/12/2018   4       
7/12/2018   4       
7/12/2018   4       
7/11/2018   4       
7/12/2018   4       
7/11/2018   4       
7/11/2018   4   7/11/2018 13:40 7/17/2018 15:00
7/12/2018   4       
7/11/2018   4       
7/11/2018   4       
7/11/2018   4       
7/13/2018   4       
7/5/2018    4       
7/5/2018    4       
7/6/2018    4       
7/6/2018    4   7/6/2018 13:00  7/10/2018 13:30
7/6/2018    4   7/6/2018 15:30  7/10/2018 13:30
7/5/2018    4       
7/5/2018    4       
7/5/2018    4       
7/5/2018    4       
7/5/2018    4       
7/5/2018    4       
7/4/2018    4       
7/4/2018    4       
7/4/2018    4   7/4/2018 11:20  7/10/2018 13:30
7/3/2018    4       
7/18/2018   4       
7/19/2018   4       
7/18/2018   4       
7/4/2018    4   7/4/2018 11:20  7/10/2018 13:30
7/17/2018   4       
7/19/2018   4       
7/20/2018   4       
7/4/2018    4   7/4/2018 11:20  7/10/2018 13:30
7/4/2018    4   7/4/2018 13:48  7/10/2018 13:30
7/5/2018    4       
7/5/2018    4       
7/5/2018    4       
7/3/2018    4   7/3/2018 12:50  7/4/2018 15:45
7/3/2018    4   7/3/2018 12:50  7/4/2018 15:45
7/3/2018    4       
7/3/2018    4   7/3/2018 12:50  7/4/2018 15:45
7/3/2018    4   7/3/2018 14:30  7/4/2018 15:45
7/3/2018    4       
7/3/2018    4   7/3/2018 12:50  7/4/2018 15:45
7/3/2018    4       
7/3/2018    4   7/3/2018 12:50  7/4/2018 15:45
7/3/2018    4       
7/6/2018    4       
7/6/2018    4       
7/5/2018    4       
7/5/2018    4   7/5/2018 16:20  7/10/2018 13:30
7/5/2018    4       
6/26/2018   4       
6/27/2018   4       
6/28/2018   4       
7/11/2018   4       
6/28/2018   4       
7/18/2018   4   7/18/2018 10:56 7/24/2018 14:30
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/18/2018   4       
7/17/2018   4       
7/17/2018   4       
7/17/2018   4   7/17/2018 13:20 7/24/2018 14:30
7/17/2018   4       
7/17/2018   4   7/17/2018 16:30 7/24/2018 14:30
7/17/2018   4       
7/17/2018   4       
7/17/2018   4       
7/17/2018   4       
7/17/2018   4       
7/19/2018   4   7/19/2018 12:50 7/24/2018 14:30
7/19/2018   4       
7/19/2018   4       
7/19/2018   4       
7/19/2018   4       
7/19/2018   4   7/19/2018 14:04 7/24/2018 14:30
7/19/2018   4       
7/19/2018   4       
7/20/2018   4       
7/20/2018   4       
7/19/2018   4   7/19/2018 12:50 7/24/2018 14:30
7/19/2018   4       
7/19/2018   4       
7/19/2018   4       
7/19/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4   7/20/2018 12:40 7/24/2018 14:30
7/19/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4       
7/24/2018   4       
7/24/2018   4       
7/24/2018   4       
7/25/2018   4       
7/24/2018   4       
7/25/2018   4       
7/25/2018   4       
7/25/2018   4       
7/25/2018   4   7/25/2018 13:00 
7/20/2018   4       
7/20/2018   4       
7/20/2018   4   7/20/2018 13:55 7/24/2018 14:30
7/23/2018   4   7/23/2018 12:48 7/24/2018 14:30
7/23/2018   4       
7/20/2018   4       
7/20/2018   4       
7/20/2018   4       
7/23/2018   4       
7/24/2018   4       
7/20/2018   4       
7/20/2018   4   7/20/2018 12:40 7/24/2018 14:30
7/20/2018   4       
7/23/2018   4       
7/25/2018   4       
7/26/2018   4       
7/25/2018   4       
7/26/2018   4       
7/25/2018   4       
7/26/2018   4       
7/27/2018   4       
7/26/2018   4       
7/27/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4   7/26/2018 14:02 
7/27/2018   4       
7/26/2018   4       
7/27/2018   4       
7/26/2018   4       
7/27/2018   4       
7/27/2018   4       
7/27/2018   4       
7/27/2018   4       
7/27/2018   4       
7/25/2018   4       
7/25/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
7/26/2018   4       
6/19/2018   3   6/18/2018 15:00 6/28/2018 11:35
6/19/2018   3       
6/19/2018   3       
6/20/2018   3       
6/20/2018   3       
6/20/2018   3       
6/20/2018   3       
6/20/2018   3       
6/21/2018   3       
6/21/2018   3       
6/21/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/26/2018   3   6/26/2018 12:35 6/28/2018 11:35
6/26/2018   3       
6/26/2018   3       
6/26/2018   3       
6/20/2018   3       
6/21/2018   3       
6/21/2018   3       
6/21/2018   3       
6/20/2018   3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
6/21/2018   3       
6/21/2018   3       
6/21/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/22/2018   3       
6/26/2018   3       
6/26/2018   3       
6/22/2018   3       
6/22/2018   3   6/22/2018 14:10 6/28/2018 11:35
6/22/2018   3       
6/26/2018   3       
6/26/2018   3   6/26/2018 12:35 6/28/2018 11:35
6/26/2018   3       
6/26/2018   3       
6/26/2018   3       
6/27/2018   3   6/27/2018 13:20 6/28/2018 11:35
6/27/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/19/2018   3       
6/19/2018   3       
6/19/2018   3       
6/20/2018   3       
6/20/2018   3       
6/26/2018   3       
6/26/2018   3       
6/26/2018   3       
6/27/2018   3   6/27/2018 13:20 6/28/2018 11:35
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/27/2018   3       
6/28/2018   3   6/28/2018 12:15 7/4/2018 10:50
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/28/2018   3   6/28/2018 15:22 7/4/2018 10:50
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/26/2018   3   6/26/2018 13:35 6/28/2018 11:35
6/26/2018   3       
6/26/2018   3       
6/26/2018   3       
6/27/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/27/2018   3       
6/27/2018   3       
6/28/2018   3   6/28/2018 12:15 7/4/2018 10:50
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/28/2018   3       
6/29/2018   3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
6/29/2018   3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/2/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/3/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3       
7/4/2018    3   7/4/2018 13:20  7/10/2018 11:15
7/4/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/9/2018    3       
7/9/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/5/2018    3       
7/9/2018    3       
7/9/2018    3       
7/9/2018    3       
7/9/2018    3       
7/9/2018    3       
7/10/2018   3       
7/10/2018   3       
7/10/2018   3       
7/11/2018   3       
7/11/2018   3       
7/5/2018    3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/9/2018    3       
7/9/2018    3       
7/9/2018    3       
7/10/2018   3       
7/10/2018   3       
7/10/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/11/2018   3       
7/12/2018   3       
7/12/2018   3       
7/12/2018   3       
7/12/2018   3       
7/12/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/18/2018   3       
7/18/2018   3       
7/18/2018   3       
7/18/2018   3       
7/20/2018   3       
7/20/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/13/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/18/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/17/2018   3       
7/18/2018   3       
7/18/2018   3       
7/18/2018   3       
7/23/2018   3       
7/23/2018   3   7/23/2018 15:10 7/24/2018 13:00
7/23/2018   3       
7/18/2018   3   7/18/2018 14:30 7/24/2018 13:00
7/18/2018   3       
7/18/2018   3       
7/18/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/20/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3   7/23/2018 15:10 7/24/2018 13:00
7/24/2018   3   7/24/2018 14:00 
7/24/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3   7/23/2018 15:10 7/24/2018 13:00
7/23/2018   3   7/23/2018 15:10 7/24/2018 13:00
7/23/2018   3   7/23/2018 15:10 7/24/2018 13:00
7/23/2018   3       
7/25/2018   3       
7/24/2018   3       
7/25/2018   3       
7/24/2018   3       
7/24/2018   3       
7/24/2018   3   7/24/2018 14:00 
7/24/2018   3       
7/24/2018   3       
7/25/2018   3   7/25/2018 15:00 
7/25/2018   3       
7/25/2018   3       
7/25/2018   3       
7/25/2018   3       
7/26/2018   3       
7/24/2018   3       
7/25/2018   3       
7/24/2018   3       
7/25/2018   3       
7/24/2018   3       
7/25/2018   3       
7/24/2018   3       
7/25/2018   3       
7/25/2018   3       
7/25/2018   3       
7/26/2018   3       
7/23/2018   3       
7/26/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/23/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/27/2018   3       
7/25/2018   3       
7/26/2018   3       
7/26/2018   3       
7/26/2018   3       
7/27/2018   3       
7/27/2018   3       

2 个答案:

答案 0 :(得分:1)

尝试使用eval

df2.dropna(axis=0, how='all', subset=['received', 'sent'])\
    .pivot_table(index='site', values=['received','sent'],\
    aggfunc='count', margins=True, dropna=False).eval('Total = received + sent')

输出:

      received  sent  Total
site                       
2           32    27     59
3           20    17     37
4           33    31     64
5           40    31     71
All        125   106    231

答案 1 :(得分:0)

df2 = pd.read_csv("https://www.dropbox.com/s/90y07129zn351z9/test_data.csv?dl=1",encoding="latin-1")

df2['received'] = pd.to_datetime(df2['received'])
df2['sent'] = pd.to_datetime(df2['sent'])

import pandas as pd
pvt_all = df2.dropna(axis=0, how='all', subset=['received', 'sent'])\
    .pivot_table(index=['site'], values=['received','sent'],\
    aggfunc='count', margins=True, dropna=False)
pvt_all['to_send']= pvt_all['received']-pvt_all['sent'] 
#pvt_all['Total'] = pvt_all.received + pvt_all.sent + pvt_all.to_send
pvt_all['Total'] = pvt_all.sum(axis=1) #Add Total column for row subtotal \
#and Total
pvt_all=pvt_all[['received','sent','to_send','Total']] 
pvt_all


received    sent    to_send Total
site                
2   32.0    27.0    5.0 64.0
3   20.0    17.0    3.0 40.0
4   33.0    31.0    2.0 66.0
5   40.0    31.0    9.0 80.0
All 125.0   106.0   19.0    250.0