如何将我的文件从 s3 加载到 powerBi? [英] How can i load my file from s3 to powerBi?

查看:11
本文介绍了如何将我的文件从 s3 加载到 powerBi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 s3 的存储桶中获取一些 csv 文件.由于没有连接器,我需要通过查询才能到达 s3.如何设置查询?

I want to get some csv files from a bucket in s3. As there is no connector, i need to go through a query to reach s3. How do i set my query ?

尝试使用邮递员并从邮递员的预览中复制信息,但无济于事.

Tried to use postman and copy the info from the preview in postman, but to no avail.

邮递员标题和网址

现在我需要在逻辑上将这些标头放入 powerBI,但是,powerBi 不能像邮递员那样进行转换.有解决办法吗?

Now i need to get those headers into powerBI logically, but, powerBi can't do the conversions like postman do. Is there a solution ?

powerBi 查询编辑器

推荐答案

好吧,我终于成功了,在powerBI里面使用了一个python脚本.

Ok, so i finally succeeded by using a python script inside powerBI.

因为 powerBI 可以使用 pyhton,你实际上可以直接从 s3 导入你的文件或对象.我需要一个 csv 文件,我用这段代码来做:

Because powerBI can use pyhton, you can actually import your files or object directly from s3. I needed one csv file and i used this code to do it:

import boto3
import pandas as pd
import io

bucket = 'name of your bucket'
key = 'name of your file'

s3 = boto3.client('s3')
f = s3.get_object(Bucket=bucket, Key=key)
shape = pd.read_csv(io.BytesIO(f['Body'].read()), header=0, index_col=0)
shape = shape.apply(lambda x: x.fillna(0))
print(shape)

这让我可以将我的对象转换为 powerBI 能够读取的 panda 数据框.确保检查 powerBI 是否使用安装了 pnada 和 io 的正确 python 环境,并且您有 boto3 以及通过 awscli 或文件凭据在 aws 中注册的凭据(同样适用于该地区).

This allowed me to transform my object into a panda dataframe, that powerBI is able to read. Make sure you check if powerBI use the correct python environment with pnada and io installed and that you have boto3 with you credentials registered in aws via awscli or in the file credentials (the same apply with the region).

这篇关于如何将我的文件从 s3 加载到 powerBi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆