[英]How to transform column values of a dataframe to another dataframe with different indexes?
[英]In Pandas Dataframe, how to get the indexes of another column base on a known values in a column?
我有一個包含多列的熊貓數據框。 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)
提前致謝!
largest = dss['length'].max()
dss[['report_end_d','report_start_d']] [dss['length'] == largest]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.