Python 在s3存储桶之间复制时过滤掉空文件
我正在使用python boto3在跨帐户s3存储桶之间复制txt文件。我正在将文件读取到熊猫数据框以进行一些清理。我注意到很多文件都是空的。在复制之前是否有方法过滤掉0B文件Python 在s3存储桶之间复制时过滤掉空文件,python,pandas,amazon-web-services,amazon-s3,boto3,Python,Pandas,Amazon Web Services,Amazon S3,Boto3,我正在使用python boto3在跨帐户s3存储桶之间复制txt文件。我正在将文件读取到熊猫数据框以进行一些清理。我注意到很多文件都是空的。在复制之前是否有方法过滤掉0B文件 谢谢 您可以创建bucket中所有文件的列表,并排除大小为0的文件。一种方法是使用以下各项: 列出存储桶中的所有文件及其大小: 使用此信息创建一个数据帧 这将返回类似于: file name file size 0
谢谢 您可以创建bucket中所有文件的列表,并排除大小为0的文件。一种方法是使用以下各项:
file name file size
0 apc/daily/ 0
1 apc/daily/2021/1/dagsrapport-2021-01-18.csv 1498
2 apc/daily/2021/1/dagsrapport-2021-01-19.csv 1498
3 apc/daily/2021/1/dagsrapport-2021-01-20.csv 1500
4 apc/daily/2021/1/dagsrapport-2021-01-21.csv 1498
... ... ...
7829 apc/vehicles/2021/4/814/0814-2021-04-19T020101... 70
7830 apc/vehicles/2021/4/814/0814-2021-04-20T020131... 8741
7831 apc/vehicles/2021/4/814/0814-2021-04-21T020128... 8719
7832 apc/vehicles/2021/4/814/0814-2021-04-22T020127... 7337
7833 apc/vehicles/2021/4/814/0814-2021-04-23T020117... 9292
你是想在下载之前检查s3上的大小,还是想在下载该特定文件之后检查大小?你能给我们看一下你的代码,让我们看看你是如何复制文件的吗?@SundeepPidugu我更愿意在从s3下载后检查。谢谢!这非常有效,我现在可以将>0B的文件复制到我的目标存储桶。很高兴这有帮助!
df = pd.DataFrame(
{'file name': my_files,
'file size': file_size
})
file name file size
0 apc/daily/ 0
1 apc/daily/2021/1/dagsrapport-2021-01-18.csv 1498
2 apc/daily/2021/1/dagsrapport-2021-01-19.csv 1498
3 apc/daily/2021/1/dagsrapport-2021-01-20.csv 1500
4 apc/daily/2021/1/dagsrapport-2021-01-21.csv 1498
... ... ...
7829 apc/vehicles/2021/4/814/0814-2021-04-19T020101... 70
7830 apc/vehicles/2021/4/814/0814-2021-04-20T020131... 8741
7831 apc/vehicles/2021/4/814/0814-2021-04-21T020128... 8719
7832 apc/vehicles/2021/4/814/0814-2021-04-22T020127... 7337
7833 apc/vehicles/2021/4/814/0814-2021-04-23T020117... 9292
df_non_empty = df[df['file size']>0]
List_non_empty = df_non_empty['file name'].to_list()