我有以下数据框:
Zone Store Department TTLSales
0 APV 220
1 APV ST12 100
2 APV ST12 Elec 40
3 APV ST12 Grocery 20
4 APV ST12 CPG 40 我希望包含一个列,将这些值连接为:
Zone Store Department TTLSales id
0 APV 220 APV
1 APV ST12 100 APV.ST12
2 APV ST12 Elec 40 APV.ST12.Elec
3 APV ST12 Grocery 20 APV.ST12.Grocery
4 APV ST12 CPG 40 APV.ST12.CPG我是熊猫的新手,已经花了很多时间,但我不能理解。
发布于 2021-07-21 19:54:44
使用以下代码
df["id"]=df["Zone"]+"."+df["Store"]+"."+df["Department"]
df["id"]=df["id"].apply(lambda x:x.rstrip("."))
df结果
Zone Store Department TTLSales id
0 APV 220 APV
1 APV ST12 100 APV.ST12
2 APV ST12 Elec 40 APV.ST12.Elec
3 APV ST12 Grocery 20 APV.ST12.Grocery
4 APV ST12 CPG 10 APV.ST12.CPGhttps://stackoverflow.com/questions/68468319
复制相似问题