我有一個包含多列的熊貓資料框。2 列(包括'report_end_d'和'report_start_d')的資料型別是日期。我想基本上得到這兩列之間的差異并找到最大長度。(我可以做到)另外,我想找到該最大值的值。我的意思是 report_end_d、report_start_d 列的日期。如果有人可以提出建議,那將是一個很大的幫助!提前致謝!
# here are my dataframe
report_sales report_end_d report_start_d
0 342 2021-09-04 00:00:00 2021-06-13 00:00:0
1 231 2021-08-29 00:00:00 2021-05-23 00:00:00
2 124 2021-09-04 00:00:00 2021-07-11 00:00:00
3 56 2021-09-04 00:00:00 2021-07-25 00:00:00
4 76 2021-08-28 00:00:00 2021-05-22 00:00:00
dss['length'] = (dss['report_end_d'] - dss['report_start_d'])
report_sales report_end_d report_start_d length
0 342 2021-09-04 00:00:00 2021-06-13 00:00:00 83 days
1 231 2021-08-29 00:00:00 2021-05-23 00:00:00 98 days
2 124 2021-09-04 00:00:00 2021-07-11 00:00:00 55 days
3 56 2021-09-04 00:00:00 2021-07-25 00:00:00 41 days
4 76 2021-08-28 00:00:00 2021-05-22 00:00:00 98 days
So I basically need either index 1 values (report_end_d as - 2021-08-29 00:00:00 report_start_d as- 2021-05-23 00:00:00) or index 4 values (report_end_d as -2021-08-28 00:00:00 report_start_d as- 2021-05-22 00:00:00)
提前致謝!
uj5u.com熱心網友回復:
largest = dss['length'].max()
dss[['report_end_d','report_start_d']] [dss['length'] == largest]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/327938.html
