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

查看:52
本文介绍了如何将文件从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能够读取的熊猫数据框.确保检查powerBI是否使用了正确的python环境,并安装了pnada和io,并且您拥有通过bows3通过awscli在aws中注册过的凭据或在文件凭据中使用的boto3(同样适用于该地区).

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天全站免登陆