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

编程入门 行业动态 更新时间:2024-10-26 10:36:25
本文介绍了Power BI中的Python脚本返回日期为Microsoft.OleDb.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

导入具有两列 [日期,值] 的csv文件并使用 Home>进行转换后。编辑查询>转换>运行Python脚本,日期列显示 Microsoft.OleDb.Date 而不是日期。在运行脚本之前,同一列中的相同值将显示为 12.10.2018 (csv的输入格式为 2018-10-12 )。这会导致查询设置中的任何后续步骤中断。您如何解决这个问题?

样本数据:

日期,值 2108-10-12,1 2108-10-13,2 2108-10-14,3 2108-10- 15,4 2108-10-16,5

代码示例:

#'dataset'保存此脚本的输入数据dataset ['Value2'] =数据集['值'] * 10 数据集

错误:

解决方案

这与针对R脚本

在执行其他任何操作之前,只需单击日期旁边的符号,然后选择文本。

现在,您可以单击运行Python脚本,插入您的代码,然后点击确定。这将带您进入最后一个中间步骤,您必须在此处单击 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 a suggestion 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

本文发布于:2023-10-30 08:07:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   日期   Python   Power   BI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!