我想筛选在以前的数据中不存在的 customer_id's
,因此所有 new_customer_ids
都是2020-01-10上新增的,而在2020-01-01上不存在
主楼
date customer_id amount_spent
2020-01-01 24 123
2020-01-10 24 145
2020-01-01 58 89
2020-01-10 58 67
2020-01-01 98 34
2020-01-10 99 86
2020-01-10 67 140
2020-01-10 32 321
2020-01-10 75 76
输出功率
new_customer_id amount_spent
32 321
75 76
67 140
我曾尝试在Pandas中使用shift功能,但这对我不起作用
编辑
df = pd.DataFrame([["2020-01-01",24,123],
["2020-01-10",24,145],
["2020-01-01",58,89],
["2020-01-10",58,67],
["2020-01-01",98,34],
["2020-01-10",98,86],
["2020-01-10",67,140],
["2020-01-10",32,321],
["2020-01-10",75,76]],columns = ["date","customer_id","amount_spent" ])
IIUC您可以获取
customer_id
中存在的2020-01-01
,然后过滤掉它们:这是另一个解决方案
假设您的示例中有一个输入错误(99是98)。您可以执行以下操作:
输出:
这需要根据df的复杂性进行编辑
相关问题 更多 >
编程相关推荐