久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 Python 在 PowerBI 中制作可重現的數據樣本

How to make a reproducible data sample in PowerBI using Python?(如何使用 Python 在 PowerBI 中制作可重現的數據樣本?)
本文介紹了如何使用 Python 在 PowerBI 中制作可重現的數據樣本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這是一個自我回答的帖子.為什么?因為缺乏數據樣本,Power BI 中的許多問題都沒有得到解答.此外,許多人似乎想知道如何使用 Python 在 Power BI 中編輯數據表.當然,世界需要在 Power BI 中更廣泛地使用 Python.有些人認為您必須將 Python 片段應用到在其他地方加載的現有表.我對這篇文章的回答將向您展示如何在一個空的 Power BI 文件中使用幾行代碼構建一個(相當大的)數據樣本.

那么,如何在 Power BI 中使用 Python 構建數據樣本并對其進行更改?

解決方案

我將向您展示如何構建包含分類值和數值的 10000 行的數據集.我正在使用 Python 庫

現在,使用 Transform >運行 Python 腳本,插入上面的代碼片段,然后點擊 OK 得到這個:

您現在有一個包含 2 列和 3 行的初步表格.這是在 Power BI 中實現 Python 的一個非常簡潔的細節.這是運行代碼片段后可供您使用的三個不同數據集.Dataset 是默認構造的,但是因為我們從一個空表開始,所以它是空的.如果我們從一些其他數據開始,Run Python Script 的第一行解釋了這個表的用途# 'dataset' 保存了這個腳本的輸入數據.它是以 pandas 數據框的形式構建的.最后一個表 df_metadata 只是我們真正感興趣的數據集的簡要描述:df_dataset,但我將其添加到混合中是為了說明所有您在片段中制作的數據框將可供您使用.您通過單擊名稱旁邊的 Table 來選擇要繼續處理的表格.

就是這樣!您現在有一個混合數據類型表,可以繼續使用 Python 或 Power BI 本身進行處理:

從這里您可以:

  1. 使用任何菜單選項繼續處理您的桌子
  2. 插入另一個 Python 腳本
  3. 復制您的原始數據框并通過右鍵單擊 Queries 下的 Table 創建一個 Reference 繼續處理另一個版本:

This is a self-answered post. Why? Because many questions in Power BI go unanswered because of lacking data samples. Also, many seem to wonder how to edit data tables in Power BI using Python. And, of course, the world needs a more wide-spread usage of Python in Power BI. Some think that you have to apply a Python snippet to an existing table loaded elsewhere. My answer to this post will show you how to build a (fairly big) data sample with a few lines of code in an otherwise empty Power BI file.

So, how can you build a data sample and make changes to it using Python in Power BI?

解決方案

I'll show you how to build a dataset of 10000 rows that contains both categorical and numerical values. I'm using the Python libraries numpy and pandas for the data generation and table operations, respectively. The snippet below simply draws a random element from two lists 10000 times to build two columns with a few street and city names, and adds a list of random numbers into the mix. Then I'm using pandas to organize the data in a dataframe. Using Python in the Power BI Power Query Editor, your input has to be a table, and your output has to be a pandas dataframe.

Python snippet:

import numpy as np
import pandas as pd

np.random.seed(123)
streets=['Broadway', 'Bowery', 'Houston Street']
cities=['New York', 'Chicago', 'Baltimore']

rows = 1000

lst_cities=np.random.choice(cities,rows).tolist()
lst_streets=np.random.choice(streets,rows).tolist()
lst_numbers= np.random.randint(low=0, high=100, size=rows).tolist()
df_dataset=pd.DataFrame({'City':lst_cities,
                      'Street':lst_streets,
                      'ID':lst_numbers})
df_metadata = pd.DataFrame([df_dataset.shape])

Power BI:

In Power BI Desktop, click Enter Data to go to the Power Query Editor. In the following dialog window, do absolutely nothing but clicking OK. The result is an empty table and two steps under Applied steps:

Now, use Transform > Run Python Script, insert the snippet above and click OK to get this:

You now have a preliminary table with 2 columns and 3 rows. And this is a pretty neat detail of the implementation of Python in Power BI. These are three different datasets that are made available to you after running your snippet. Dataset is constructed by default, but is empty since we started out with an empty table. If we started out with some other data, the first line of the Run Python Script explains the purpose of this table # 'dataset' holds the input data for this script. And it is constructed in the form of a pandas dataframe. The last table df_metadata is only a brief description of the dataset we're really interested in: df_dataset, but I've added it to the mix in order to illustrate that all dataframes made by you in your snippet will be available to you. You chose which table to continue working on by clicking Table next to the name.

And that's it! You now have a table of mixed datatypes to keep working on either using Python or Power BI itself:

From here you can:

  1. Keep working on your table using any menu option
  2. Insert another Python script
  3. Duplicate your original dataframe and keep working on another version by creating a Reference by right-clicking Table under Queries:

這篇關于如何使用 Python 在 PowerBI 中制作可重現的數據樣本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 国产精品高清在线 | 久久久噜噜噜www成人网 | 亚洲成人精品影院 | 久久免费视频在线 | www国产成人免费观看视频,深夜成人网 | 欧美精品一区二区三区四区五区 | 男女羞羞视频在线看 | 91网站在线观看视频 | 久久久精品视频免费 | 免费同性女女aaa免费网站 | 亚洲国产成人精品女人久久久 | 国产高清一区二区 | 中文字幕第二十页 | 黄色欧美在线 | 日韩一区二区三区在线视频 | 国产成人精品久久二区二区91 | 国产免国产免费 | 99久久电影| 精品久久久久久亚洲精品 | 99国产精品99久久久久久 | 国产福利免费视频 | 在线视频中文字幕 | 日本精品视频 | 亚洲性在线 | 91在线视频免费观看 | 久久成人精品 | 青青草av网站 | 日韩有码一区 | 久久男人| 欧美操操操 | 免费观看国产视频在线 | 国产高清在线观看 | 国产日韩欧美在线观看 | 久在线视频播放免费视频 | 国产国语精品 | 一区二区三区不卡视频 | 精品国产乱码久久久久久丨区2区 | 久久久久se | 欧美日韩不卡合集视频 | 黄色免费在线网址 | 中文字幕在线播放第一页 |