You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power BI中Matplotlib可视化的日期时间格式转换问题求助

Power BI中Python脚本处理日期及图表生成问题

操作流程

  • 数据源为Excel文件
  • 在Power Query中依次执行:
    • 将所有列转为文本格式
    • 运行Python脚本填充dataset数据框
    • 获取文本格式数据集
    • 将所有内容转回数据格式

问题详情

日期转换失败(步骤6)

ISO 8601格式的日期字段,使用pd.to_datetime()、datetime.date.fromisoformat()均无法转换为日期类型。

图表生成异常(步骤7)

除日期转换失败外,频繁出现NaT错误,导致Matplotlib无法生成图表。

背景说明

将所有列转为文本格式的操作,参考了Stack Overflow相关解决方案。

当前使用的Python代码

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset = pandas.DataFrame(Scale, Y 1, Y 2, Y 3, Y 4, Y 5, Y 6)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime

plt.figure(figsize=(15, 16))

# In below plot everything is text (ISO 8601 format) and not date
#plt.plot(dataset['Scale'],dataset['Scale'])

#Below line does not create any plot at all
plt.plot(dataset['Y 1'],dataset['Y 1'])

plt.show()

操作步骤截图

操作步骤截图1
操作步骤截图2
操作步骤截图3
操作步骤截图4
操作步骤截图5
操作步骤截图6
操作步骤截图7
操作步骤截图8

内容的提问来源于stack exchange,提问作者user18884753

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 03:27:53