python - 无法从 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)
解决方案
推荐阅读
- javascript - 如何通过 1 次点击而不是 2 次在移动设备上提交联系表单
- python-3.x - 使用python和re获取2个字符串之间的数据
- bash - yq 读取以获取数组元素
- javascript - 使用 if 语句在数字为 15 时进行页面重定向
- r - R中的误差线和几何点问题
- c# - PrintPreviewControl HitTest() 和交互
- html - 如何使图片适合半圆
- javascript - express js内部服务器错误500,代码中没有错误
- html - 在 RStudio 中从 HTML 中检索数据
- python - JupyterLab 中的散景滑块未更新