简体   繁体   English

如何基于Pandas DataFrame中另一列的多个唯一值来合并一列的总和?

[英]How to combine the sum of one column based on multiple unique values of another column in Pandas DataFrame?

I'm looking to combine the sum of Sales_volume($) column, based on unique values in the Store_name column. 我想根据Store_name列中的唯一值来合并Sales_volume($)列的总和。 Not sure if this is possible, but here is my DataFrame: 不知道这是否可能,但这是我的DataFrame:

    Store_name  Sales_volume($) Date    
0   store 167   1.00               2019-06-03
1   store 167   4.00               2019-06-03
2   store 177   3.37               2019-06-03
3   store 177   2.14               2019-06-03
4   store 216   7.96               2019-06-03
5   store 216   1.99               2019-06-03

My desired output: 我想要的输出:

    Store_name  Sales_volume($) Date    
0   store 167   5.00               2019-06-03
1   store 177   5.51               2019-06-03
2   store 216   9.95               2019-06-03

Thanks! 谢谢!

据我了解,您想按Store_name对数据进行Store_name并获取商店的Sales总和: df.groupby('Store_name').sum()或者是否要为每个日期的商店都有Sales: df.groupby(['Store_name','Date']).sum()

暂无
暂无

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

相关问题 Pandas,根据一列中的唯一值和另一列中的 grouby 筛选 dataframe - Pandas, filter dataframe based on unique values in one column and grouby in another 熊猫如何对一个列进行分组并根据另一列的最小唯一值过滤数据框? - How to pandas groupby one column and filter dataframe based on the minimum unique values of another column? 基于多列和一列总和重新排序熊猫数据框 - Reordering pandas dataframe based on multiple column and sum of one column 如何将一个熊猫数据框的一列与另一个数据框的每一列相加? - How to sum a column of one pandas dataframe to each column of another dataframe? 如何使用非唯一列将具有求和值的熊猫Groupby数据框映射到另一个数据框 - How to map pandas Groupby dataframe with sum values to another dataframe using non-unique column 基于 Pandas DataFrame 中另一列的 Sum 列 - Sum column based on another column in Pandas DataFrame pandas数据框根据另一数据框中的值将值追加到一列 - pandas dataframe append values to one column based on the values in another dataframe Python Pandas DataFrame - 如何根据另一列(日期类型)中的部分匹配对 1 列中的值求和? - Python Pandas DataFrame - How to sum values in 1 column based on partial match in another column (date type)? 根据熊猫数据框中的另一列值计算值的总和? - Calculate the sum of values based on another column value in pandas dataframe? pandas DataFrame:根据另一列中的 boolean 值计算 Sum - pandas DataFrame: Calculate Sum based on boolean values in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM