Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我见过这样的pandasql查询:
pandasql
df = pd.DataFrame({'A': [1, 2, 2], 'B': [3, 4, 5]}) sqldf('select * from df group by A', locals())
这给出了:
A B 0 1 3 1 2 6
我发现没有聚合函数的 group by 真的很奇怪,但是谁能告诉我聚合列上使用了哪个函数来将多个值减少为一个?
看起来您正在寻找的 groupby 方法是last():
last()
df = pd.DataFrame({'A': [1, 2, 2], 'B': [3, 4, 5]}) df.groupby('A', as_index=False).last()
输出:
A B 0 1 3 1 2 5
我这么说是假设 5 是一个错字(请参阅我上面的评论)并且应该是 6。