Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中将多个索引的累积数据转换为每日数据?_Python_Pandas_Numpy_Dataframe - Fatal编程技术网

如何在python中将多个索引的累积数据转换为每日数据?

如何在python中将多个索引的累积数据转换为每日数据?,python,pandas,numpy,dataframe,Python,Pandas,Numpy,Dataframe,我有以下形式的数据集- date code A B C 20-02-01 box1 1 2 1 20-02-02 box1 2 2 1 20-02-03 box1 3 2 1 20-02-01 box2 2 1 1 20-02-04 box3 4 2 1 20-02-05 box3 5 2 1 20-02-06 box3 7 2 1 A、B、C列表示每个框在第一列中给出的日期内的累积值。 现在我想创建另

我有以下形式的数据集-

date      code     A B C
20-02-01  box1     1 2 1
20-02-02  box1     2 2 1
20-02-03  box1     3 2 1
20-02-01  box2     2 1 1
20-02-04  box3     4 2 1
20-02-05  box3     5 2 1
20-02-06  box3     7 2 1 

A、B、C列表示每个框在第一列中给出的日期内的累积值。 现在我想创建另一行,它可以在python中找到每一个框的w.r.t.的每日增长。 例如,最终结果应为-

date      code     A B C D
20-02-01  box1     1 2 1 1
20-02-02  box1     2 2 1 1
20-02-03  box1     3 2 1 1
20-02-01  box2     2 1 1 2 
20-02-04  box3     4 2 1 4 
20-02-05  box3     5 2 1 1 
20-02-06  box3     7 2 1 2 

如何根据两个索引(日期、代码)找到A中的差异?

您可以使用
code
对数据帧进行分组,然后在
A列上使用
A列
您可以通过使用函数的组合找到
A列
中的每日增加量,&:

结果:

# print(df)
       date  code  A  B  C  D
0  20-02-01  box1  1  2  1  1
1  20-02-02  box1  2  2  1  1
2  20-02-03  box1  3  2  1  1
3  20-02-01  box2  2  1  1  2
4  20-02-04  box3  4  2  1  4
5  20-02-05  box3  5  2  1  1
6  20-02-06  box3  7  2  1  2
# print(df)
       date  code  A  B  C  D
0  20-02-01  box1  1  2  1  1
1  20-02-02  box1  2  2  1  1
2  20-02-03  box1  3  2  1  1
3  20-02-01  box2  2  1  1  2
4  20-02-04  box3  4  2  1  4
5  20-02-05  box3  5  2  1  1
6  20-02-06  box3  7  2  1  2