Home  >  Q&A  >  body text

python - pandas How to "quickly" get the first and last rows of tens of millions of data groups?

I hope to get the first and last rows of each group after pandas grouping. The current method is to traverse the group for name, group in xxx: then group.iloc[0] group.iloc[-1], but this Traversing tens of millions of data is very slow. Is there any fast method?

大家讲道理大家讲道理2712 days ago1013

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 10:50:04

    You can use the groupbys method of DataFrame to return the first and last methods of the object to obtain it

    reply
    0
  • Cancelreply