获取上次 PR 的日期

问题描述 投票:0回答:1

我想返回 LINE 为 PR 的每一行的完成日期。 请不要交叉连接,该表有数百万条记录。

地点 线 开始 完成
10003281 P 2024年8月30日 2024年8月30日
10003281 P 2024年3月22日 2024年3月22日
10003281 公关 2024年2月13日
10003281 P 2024年2月13日 2024年2月13日
10003281 P 2023年12月18日 11-01-2024
10003281 P 2023年11月21日 2023年11月21日
10003281 P 2023年7月8日 2023年10月11日
10003281 公关 2023年7月8日

预期结果应该是

地点 线 开始 完成 PRD日期
10003281 P 2024年8月30日 2024年8月30日 2024年2月13日
10003281 P 2024年3月22日 2024年3月22日 2024年2月13日
10003281 公关 2024年2月13日 2024年2月13日
10003281 P 2024年2月13日 2024年2月13日 2023年7月8日
10003281 P 2023年12月18日 11-01-2024 2023年7月8日
10003281 P 2023年11月21日 2023年11月21日 2023年7月8日
10003281 P 2023年7月8日 2023年10月11日 2023年7月8日
10003281 公关 2023年7月8日 2023年7月8日
t-sql snowflake-cloud-data-platform
1个回答
0
投票

我假设您的表格采用 csv 格式,因为您没有提供有关表格格式的信息。我将使用 csv Python 库。如果你安装了 Pandas 库,你也可以使用它,但这是一个简单的方法。

import csv

# Open the CSV file
with open('yourfile.csv', mode='r') as file:
    reader = csv.DictReader(file)
    
    # Loop through each row in the CSV
    for row in reader:
        # Check if the Line column contains 'PR'
        if row['Line'] == 'PR':
            print(row)

这将循环遍历您的 csv 文件并检查行列是否为“PR”。当它是“PR”时,它会打印该行。如果你想在第一个“PR”处停止,只需在之后调用break即可。我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.