Hướng dẫn dùng pandas.idxmax python
Return index of first occurrence of maximum over requested axis. NA/null values are excluded. The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise. Exclude NA/null values. If an entire row/column is NA, the result will be NA. Indexes of maxima along the specified axis. If the row/column is empty Notes This method is the DataFrame version of Examples Consider a dataset containing food consumption in Argentina. >>> df = pd.DataFrame({'consumption': [10.51, 103.11, 55.48], ... 'co2_emissions': [37.2, 19.66, 1712]}, ... index=['Pork', 'Wheat Products', 'Beef']) >>> df consumption co2_emissions Pork 10.51 37.20 Wheat Products 103.11 19.66 Beef 55.48 1712.00 By default, it returns the index for the maximum value in each column. >>> df.idxmax() consumption Wheat Products co2_emissions Beef dtype: object To return the index for the maximum value in each row, use >>> df.idxmax(axis="columns") Pork co2_emissions Wheat Products consumption Beef co2_emissions dtype: object Tôi có một khung dữ liệu được tạo qua df.pivot:
Tôi muốn lọc và trả về một hàng cho mỗi 'F_TYPE' chỉ trả về hàng có 'to_date' Tối đa. Tôi muốn trả lại khung dữ liệu sau:
Cảm ơn..
26 hữu ích 1 bình luận 38k xem chia sẻ answer 61 Một cách tiếp cận tiêu chuẩn là sử dụng Khi bạn nhận được các giá trị chỉ mục từ đó,
Lưu ý: 61 hữu ích 1 bình luận chia sẻ answer 4 Các cách khác để làm điều đó như sau:
4 hữu ích 2 bình luận chia sẻ Đăng nhập để trả lời câu hỏiCó thể bạn quan tâm |