Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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 3.x 为数据帧列表聚合数据_Python 3.x_Pandas_Dataframe_Aggregate - Fatal编程技术网

Python 3.x 为数据帧列表聚合数据

Python 3.x 为数据帧列表聚合数据,python-3.x,pandas,dataframe,aggregate,Python 3.x,Pandas,Dataframe,Aggregate,我有一个这样的数据帧列表 Name Product Quantity 0 A 1010 10 1 A 2010 12 2 B 4145 18 3 B 5225 14 4 B 6223 16 5 C 7222 18 Name Product Quantity 0 A 1010 14 1 A 2010

我有一个这样的数据帧列表

   Name  Product    Quantity
0  A     1010       10
1  A     2010       12
2  B     4145       18
3  B     5225       14
4  B     6223       16
5  C     7222       18

   Name  Product    Quantity
0  A     1010       14
1  A     2010       12
2  B     4145       21
3  B     5225       18
4  B     7565       19
5  C     7222       11

   Name  Product    Quantity
0  A     1010       15
1  A     2010       14
2  B     4145       13
3  B     5225       15
4  B     7565       17
从上面的列表中,我想得到每个同名产品的平均数量(四舍五入)

需要的产出是

   Name  Product    Avg Quantity
0  A     1010       13
1  A     2010       13
2  B     4145       17
3  B     5225       16
4  B     6223       5
5  B     7565       12
6  C     7222       10     
目前,我不知道如何在
pandas
中实现这一点,除非我将每个数据框保存到excel文件/表格中,并将它们合并到excel中。我不想走那条路线,我喜欢在熊猫里走


我能找到的最接近以前的帖子是。然而,这没有帮助。任何建议都有助于实现我的产出

So
concat
首先使用所有dfs,然后使用
groupby
mean

yourdf=pd.concat([df1,df2,df3]).groupby(['Name','Product'])['Quantity'].mean().reset_index()
yourdf
Out[410]: 
  Name  Product   Quantity
0    A     1010  13.000000
1    A     2010  12.666667
2    B     4145  17.333333
3    B     5225  15.666667
4    B     6223  16.000000
5    B     7565  18.000000
6    C     7222  14.500000