Power BI 中的 Python 脚本将日期返回为 Microsoft.OleDb.Date

Python script in Power BI returns date as Microsoft.OleDb.Date(Power BI 中的 Python 脚本将日期返回为 Microsoft.OleDb.Date)
本文介绍了Power BI 中的 Python 脚本将日期返回为 Microsoft.OleDb.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

导入包含两列 [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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

python arbitrarily incrementing an iterator inside a loop(python在循环内任意递增迭代器)
Joining a set of ordered-integer yielding Python iterators(加入一组产生 Python 迭代器的有序整数)
Iterating over dictionary items(), values(), keys() in Python 3(在 Python 3 中迭代字典 items()、values()、keys())
What is the Perl version of a Python iterator?(Python 迭代器的 Perl 版本是什么?)
How to create a generator/iterator with the Python C API?(如何使用 Python C API 创建生成器/迭代器?)
Python generator behaviour(Python 生成器行为)