csv S3中两个版本文件之间的差异

lawou6xi  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(128)

我在S3中有一个启用了版本控制的存储桶。有一个文件进来并更新其内容。该文件中有一个唯一标识符,有时新文件进来时,现有文件的内容不存在,需要保留。我的目标是有一个文件,其中包含新文件的所有内容和旧文件中不存在的所有内容。
我有一个小的python脚本来完成这项工作,我也可以在S3触发器上安排它,但是这个问题有任何AWS实现吗?比如使用S3 -〉XXXX服务,它会在文件之间给予更改(虽然不是逐行),并可能创建一个新文件。
我的python代码看起来像这样:

old_file = 'file1.1.txt'
    new_file = 'file1.2.txt'
    output_file = 'output_pd.txt'

    # Read the old file into a Pandas dataframe
    old_df = pd.read_csv(old_file, sep="\t", header=None)
    # car_df = pd.read_csv(car_file, sep="\t")
    new_df = pd.read_csv(new_file, sep="\t", header=None)

    # Find the values that are present in the old file and missing in the new file
    missing_values = old_df[~old_df.iloc[:,0].isin(new_df.iloc[:,0])]

    # Append the missing values to the new file
    final_df = new_df.append(missing_values, ignore_index=True)

    # Write the final dataframe to a new file
    final_df.to_csv(output_file, sep=' ', index=False, header=None)

但是在寻找一些原生AWS解决方案/最佳实践。

eqzww0vc

eqzww0vc1#

但是对于这个问题有AWS实现吗?
不,没有任何原生AWS实现可以比较文件内容。你必须自己实现,就像你现在做的那样。你可以托管你的代码,因为S3上传会自动触发一个lambda函数。

相关问题