简体   繁体   中英

Use Python script to create new table from current dataset in PowerBI

I'm having a csv file as a source dataset. Currently in the table there is a column that I would like to use Python to loop and extract data from string in each cell. For example, in a cell:

"Quantity changed by 10, Price changed by 90."

I would like to use Python and extract "Quantity, Price" and "10, 90" to create new table with those properties and values. Then use PowerBI Visual to create visuals instead of using Python visual. How should I do that? And is that possible at all?

Edit: Due to all the confusions, I'm adding a screenshot of the column I'm working with.

在此处输入图像描述

I would like to go through all rows in the Properties column, get data in each cell, then extract them to create a new table. For example, in this case, the new table will be like:

Properties | Value Unconnected Height | -2800 Area | -39.883

Regarding code, I have nothing yet, just the base Python snippet PowerBI created:

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset = pandas.DataFrame(Properties)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:

So PowerBI is using pandas and matplotlib to get data and plot data. But I only want to get data and output as a new table. If Python is not possible, is there a way to use Query?

Extracting the data from the column is fairly easy if the data follows the same format:

s = "Quantity changed by 10, Price changed by 90."
l, sep, r = s.partition(',')
if sep:
    quantity = int(l.split()[-1])
    price = int(r.split()[-1][:-1])
    print(quantity, price)

#10 90

The string contained in the cell is partitioned by the comma to separate the quantity and price strings, then each string it processed to extract the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM