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

As of today, August 9 2018, Power BI supports Python Visualizations. They've had support for R Visualizations before, but I still find these integrations to be a bit awkward. Let me show you what I mean:

Let's say that you have a table with time series data, where the top row containts the names 'Date' and 'Value', and the contents are dates of the form yyyy-mm-dd and a number, respectively:

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

If you store that dataset as a textfile like timerseries.csv and import it using Get Data | Text/CSV, you get a table uner VISUALIZATIONS | FIELDS, like this:

You can inspect your table using VISUALIZATIONS | Table and get:

With this setup, one should think that you were all set for unleashing the power of a Py VISUALIZATION using this beautiful new feature:

If you click that, you get this:

And you're told to

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

scripting

If you start with Value, you get this default setup in the editor:

And if you follow the instructions given by the Power BI team in the August 2018 feature summary you should be able to make a matplotlib plot quite easily.

But this is where it ends for me at the time being.

If the default dataframe in the editor shares the features of a standard dataframe, you should be able to reference a column in that dataframe and easily make a plot with this snippet:

import matplotlib.pyplot as plt

plt.plot(dataset['Value'])

plt.show()

But when you run it, it onlu returns an error:

And the details are elaborate to say the least.

I've also tried to import both Dates and Values, and I've tried plotting the dataframe directly with dataset.plot(), but nothing seems to be working. I've also tried stripping the date hierarchy down to simple dates this way:

So, any ideas on the dataformat, import method and/or the snippet?

Thank you for any suggestions!

EDIT 1 - Following the answer from Foxan Ng:

Add both columns in the Value field:

This still returns an error edning with:

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

解决方案

I didn't encounter errors that you've mentioned. Have you dropped in both columns into Values?

import matplotlib.pyplot as plt

plt.plot(dataset['Date'], dataset['Value'])

plt.show()

UPDATED with M query:

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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值