[英]pandas aggregation on multiple string columns
below is the source dataframe下面是源dataframe
a = [
['T1', 'R1', 1, 'a,b', 'E'],
['T1', 'R1', 2, 'c,d', 'F'],
['T1', 'R2', 1, 'e,f', 'G'],
['T1', 'R2', 4, 'g,h', 'H'],
['T2', 'R1', 1, 'i,j', 'I'],
['T2', 'R1', 1, 'k,l', 'J'],
]
df = pd.DataFrame(a, columns = ['t_id', 'r_id', 'al', 'mt', 'mt_type'])
group by to be done on t_id,r_id columns and aggregation to be done on these columns ['al', 'mt', 'mt_type']对 t_id,r_id 列进行分组,对这些列进行聚合 ['al', 'mt', 'mt_type']
result dataframe should look like this结果 dataframe 应该是这样的
t_id r_id al mt mt_type
0 T1 R1 2 a,b|c,d E,F
1 T1 R2 4 e,f|g,h G,H
2 T2 R1 1 i,j|k,l I,J
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.