我想删除基于列id的重复项,如果它不包含国家1或国家2中的单词us,我该如何实现这一点。
ID country1 country2 status
1. us,yt au,in,sg monetize
1. tr,hk ds,gh block
2. ju te,yu,us block
2. ju te,yu block
Expected output
ID country1. country2. status
1. us,yt au,in,sg monetize
2. ju te,yu,us block发布于 2020-03-03 05:57:43
尝试:
df["key"]=df["country1"].str.contains("us")| df["country2"].str.contains("us")
df=df.sort_values("key", ascending=False).drop_duplicates(subset="ID", keep="first").drop(columns=["key"])输出:
ID country1 country2 status
0 1. us,yt au,in,sg monetize
2 2. ju te,yu,us blockhttps://stackoverflow.com/questions/60497220
复制相似问题