我有下一张table。
import pandas as pd
# Define the input data
data = {
'ID': [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3],
'count': [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,1,1,1,1,2,2,1,1,1,1,2],
'priority': [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,4,3,1,2,3,4,4],
'item': ['A','B','C','D','A','B','C','D','A','B','C','D','A','B','C','D','A','B','C','D','D','C','A','B','C','D','D'],
'c': ['XX','XX','XX','XX','YY-SS','YY','YY','YY','YY-SS','YY','YY','YY','XX','XX','XX','XX','ZZ','ZZ','ZZ','ZZ','ZZ','ZZ','TT-SS','ZZ','ZZ','ZZ','ZZ']
}
# Convert the input data to a Pandas DataFrame
df = pd.DataFrame(data)
我需要转换这个输入,你可以在下面的输出示例中看到:在此输入图像描述
如果你有任何想法请分享。非常感谢!
1条答案
按热度按时间mrwjdhj31#
您可以使用自定义
groupby.agg
:输出: