首页 > 解决方案 > 无法从 S3 存储桶读取 excel 文件

问题描述

我有一小段代码在本地系统中运行

import pandas as pd
import glob
import openpyxl

# path of folder
path=r'C:\Users\Preet\Desktop\python_files'

#Display list of files
filenames=glob.glob(path+"\*.xlsx")
print(filenames)

#initializing data frame
finalexcelsheet=pd.DataFrame()

#to iteriate excel
for file in filenames:
    df = pd.concat(pd.read_excel(file,sheet_name=None), ignore_index=True,sort=False)

    #print(df)
    finalexcelsheet=finalexcelsheet.append(df,ignore_index=True)
print(finalexcelsheet)
finalexcelsheet.to_excel('C:\\Users\\preet\\Desktop\\python_files\\final.xlsx',index=False).

但是,当我尝试从 s3 存储桶中读取相同的 xlsx 文件时,它只会创建一个空数据框并停止并说作业成功。下面是 s3 的代码。如果下面的代码中缺少任何内容,请告诉我

import boto3
import pandas as pd
import glob
import openpyxl

# path of folder

bucketname = "sit-bucket-lake-raw-static-5464"
s3 = boto3.resource('s3')
my_bucket = s3.Bucket(bucketname)
source = "sit-bucket-lake-raw-static-5464/Staging/"
target = "sit-bucket-lake-raw-static-5464/branch/2020/12/"

#Display list of files
filenames=glob.glob(source+"\*.xlsx")
print(filenames)

#initializing data frame
finalexcelsheet=pd.DataFrame()

#to iteriate excel
for file in filenames:
    df = pd.concat(pd.read_excel(file,sheet_name=None), ignore_index=True,sort=False)

finalexcelsheet=finalexcelsheet.append(df,ignore_index=True)
print(finalexcelsheet)
finalexcelsheet.to_excel('target\final.xlsx',index=False)

标签: pythonamazon-web-servicesamazon-s3aws-glue

解决方案


推荐阅读