gpt4 book ai didi

python - Power BI 中 Python 可视化中时间序列的最佳数据格式是什么?

转载 作者:行者123 更新时间:2023-11-28 17:04:45 25 4
gpt4 key购买 nike

截至 2018 年 8 月 9 日,Power BI 支持 Python 可视化。他们之前支持 R Visualizations,但我仍然觉得这些集成有点尴尬。让我告诉你我的意思:


假设您有一个包含时间序列数据的表格,其中第一行包含名称“日期”和“值”,内容分别是 yyyy-mm-dd 形式的日期和一个数字:

Date,Value
2017-01-12,1
2017-01-13,4
2017-01-14,2
2017-01-15,4
2017-01-16,2
2017-01-17,2
2017-01-18,2
2017-01-19,5
2017-01-20,5
2017-01-21,5
2017-01-22,5
2017-01-23,6
2017-01-24,3
2017-01-25,6
2017-01-26,6
2017-01-27,5
2017-01-28,8
2017-01-29,4
2017-01-30,2

如果您将该数据集存储为文本文件,如 timerseries.csv 并使用 Get Data | 导入它文本/CSV,你得到一个表格 uner VISUALIZATIONS | FIELDS,像这样:

enter image description here

您可以使用VISUALIZATIONS | 检查您的表格表并得到:

enter image description here

有了这个设置,人们应该认为您已经准备好使用这个漂亮的新功能释放 Py VISUALIZATION 的力量:

enter image description here

如果你点击它,你会得到这个:

enter image description here

你被告知

Drag fields into the Values area in the Visualization pane to start scripting

如果您从 Value 开始,您将在编辑器中获得此默认设置:

enter image description here

如果您按照 Power BI 团队在 August 2018 feature summary 中给出的说明进行操作你应该能够很容易地制作 matplotlib 绘图。

enter image description here

但这就是目前对我来说结束的地方。

如果编辑器中的默认数据框具有标准数据框的特征,您应该能够引用该数据框中的列并使用以下代码片段轻松绘制图表:

import matplotlib.pyplot as plt
plt.plot(dataset['Value'])
plt.show()

但是当你运行它时,它只会返回一个错误:

enter image description here

至少可以说细节很详细。

我还尝试导入 DatesValues,并且尝试直接使用 dataset.plot() 绘制数据框>,但似乎没有任何效果。我还尝试通过这种方式将日期层次结构剥离为简单的日期:

enter image description here

那么,关于数据格式、导入方法和/或代码段有什么想法吗?

感谢您的任何建议!

编辑 1 - 根据 Foxan Ng 的回答:

在值字段中添加两列:

enter image description here

这仍然会返回错误编辑:

TypeError: from_bounds() takes 4 positional arguments but 6 were given

最佳答案

我没有遇到您提到的错误。您是否已将两列都放入 Values 中?

import matplotlib.pyplot as plt
plt.plot(dataset['Date'], dataset['Value'])
plt.show()

images


更新了 M 查询:

let
Source = Csv.Document(File.Contents("C:\your-directory..\timerseries.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Value", Int64.Type}})
in
#"Changed Type"

timeseries

关于python - Power BI 中 Python 可视化中时间序列的最佳数据格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51761926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com