問題描述
導入包含兩列 [Date, Value]
的 csv 文件并使用 Home > 對其進行轉換后編輯查詢 >變換>運行 Python 腳本
,Date
列顯示 Microsoft.OleDb.Date
而不是日期.在運行腳本之前,同一列中的相同值顯示為 12.10.2018
(來自 csv 的輸入格式為 2018-10-12
).這會導致 Query Settings
中的任何后續步驟中斷.你如何解決這個問題?
樣本數據:
日期、數值2108-10-12,12108-10-13,22108-10-14,32108-10-15,42108-10-16,5
代碼示例:
# 'dataset' 保存此腳本的輸入數據數據集['Value2'] = 數據集['Value']*10數據集
錯誤:
這與 R 腳本描述的問題相同
在您執行任何其他操作之前,只需單擊日期旁邊的符號并選擇 Text
.
現在你可以點擊Run Python Script
,插入你的代碼然后點擊OK
.這會將您帶到最后一個中間步驟,您必須在此處單擊 Table
:
就是這樣:
請注意,Date
的數據類型已更改為日期格式.如果沒有,您可以使用上面說明的右鍵單擊下拉菜單輕松地再次更改它.
After importing a csv file with two columns [Date, Value]
and transforming it using Home > Edit Queries > Transform > Run Python Script
, the Date
column shows Microsoft.OleDb.Date
instead of dates. Before running the script, the same values in the same column are displayed as 12.10.2018
(input format from csv is 2018-10-12
). This causes any later step in Query Settings
to break. How do you work around this?
Sample data:
Date,Value
2108-10-12,1
2108-10-13,2
2108-10-14,3
2108-10-15,4
2108-10-16,5
Code example:
# 'dataset' holds the input data for this script
dataset['Value2'] = dataset['Value']*10
dataset
Error:
This is the same issue as described for R scripts here, but for the sake of clarity, I'll add an answer for Python in Power BI as well.
Short answer:
Just change the Date
data type from date
to Text
before you insert the Python Script.
The details:
If you import the csv file using the Home > Get Data
functionality, and then go to Home > Edit Queries
, this is what you'll see:
Before you do anything else, just click on the symbol next to date and select Text
.
Now you can click Run Python Script
, insert your code and clikc OK
. This takes you to one last intermediate step where you'll have to click Table
here:
This is it:
Notice that the datatype of Date
is changed to a date format. If not you can easily change it again with the right-click drop-down menu as explained above.
這篇關于Power BI 中的 Python 腳本將日期返回為 Microsoft.OleDb.Date的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!