A B
1 10
1 20
2 30
2 40
3 10Should turn into this:
A B
1 20
2 40
3 10
if I use `df.drop_duplicates(subset=['A'], keep=max)` or change max to other functions. Is there a univsersal method to do this in pandas? Or does the developer plan to add this?
Thanks
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
A |
B | |
|---|---|---|
| 0 | 1 | 10 |
| 1 | 1 | 20 |
| 2 | 2 | 30 |
| 3 | 2 | 40 |
| 4 | 3 | 10 |
| B | |
|---|---|
| A |
| 1 | 20 |
|---|---|
| 2 | 40 |
| 3 | 10 |
| A | B | |
|---|---|---|
| 0 | 1 | 20 |
| 1 | 2 | 40 |
| 2 | 3 | 10 |
You might try sorting and then keeping the first (or last): `df.sort_values(['A', 'B'], ascending=False).drop_duplicates(subset=["A"], keep="first")`.
On Mon, May 8, 2017 at 8:22 AM, 进陆 <lepto....@gmail.com> wrote:
-- You received this message because you are subscribed to the Google Groups "PyData" group. To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
-- You received this message because you are subscribed to the Google Groups "PyData" group. To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.