如何绘制使用 Excel 的默认导入向导导入的 csv 数据?

How do I plot csv data imported using Excel's default import wizard?

我 运行 在尝试绘制从 csv 文件导入到 Excel 的数据时遇到了问题。我过去使用旧版本的 Microsoft Excel 绘制过这样的 csv 文件,但最新版本的 Excel 给我带来了问题。

首先,我通过导航至 Data>From Text/CSV> 从我的 csv 文件导入数据,然后 selecting csv 文件,>导入>加载。数据似乎 已正确导入。但是当我 select 我的数据并点击 Insert>Scatter with Smooth Lines 时,它没有正确绘制图表: Default Wizard's Resulting Graph (Actual Result).

文件>选项>数据启用旧版向导并从数据>获取数据>旧版向导>从文本(旧版)导入csv文件后),可以像旧版本的 Excel 那样绘制数据:Legacy Wizard's Resulting Graph (Desired Result).

请注意,对于这两种情况,我 select 编辑了相同的单元格,然后绘制了数据。但在默认向导中,它不起作用。当我尝试 select 单独列时,y 值全部变为 0;类似于 this unanswered query。我尝试将格式转换为“数字”而不是“常规”,但没有帮助。

如何绘制使用最新版本 Excel 导入的 csv 数据?提前致谢!

编辑:这是供参考的原始 CSV 文件

Time of Export: 2021-03-30 1:10:00,,,,
Start Date / Time: 2021-03-30 12:00:00,,,,
End Date / Time: 2021-03-30 12:30:00,,,,
Sample Rate: 1 minute(s),,,,
,Temperature Probe 1,Temperature Probe 2,Temperature Probe 3,Temperature Probe 4
TimeStamp,TP 1001 temperature (ーC),TP 1002 temperature (ーC),TP 1003 temperature (ーC),TP 1004 temperature (ーC)
2/2/2021 12:00,23.23676,0,20.62355,21.99797
2/2/2021 12:01,22.48625,0,20.65972,21.84425
2/2/2021 12:02,21.63628,0,20.53313,21.84425
2/2/2021 12:03,20.52409,0,20.3975,21.70863
2/2/2021 12:04,19.23105,0,20.44271,21.6815
2/2/2021 12:05,17.82046,0,20.30708,21.49161
2/2/2021 12:06,16.2019,0,20.23473,21.18417
2/2/2021 12:07,14.29398,0,19.76454,20.99429
2/2/2021 12:08,12.23235,0,19.49327,20.55122
2/2/2021 12:09,9.998917,0,18.95074,19.89113
2/2/2021 12:10,7.964409,0,18.30874,19.42094
2/2/2021 12:11,5.749062,0,17.60344,18.68851
2/2/2021 12:12,3.316696,0,17.27792,18.12789
2/2/2021 12:13,1.11039,0,16.52741,17.63961
2/2/2021 12:14,-1.493782,0,15.50564,16.91623
2/2/2021 12:15,-3.645836,0,14.65567,16.22902
2/2/2021 12:16,-5.598961,0,13.49826,15.11683
2/2/2021 12:17,-7.714844,0,12.57595,14.48387
2/2/2021 12:18,-9.866898,0,11.40046,13.3988
2/2/2021 12:19,-11.69344,0,11.21058,12.9919
2/2/2021 12:20,-14.09867,0,10.22497,12.12384
2/2/2021 12:21,-16.55816,0,9.519676,11.59035
2/2/2021 12:22,-18.64692,0,8.588326,10.8308
2/2/2021 12:23,-20.63622,0,7.693146,10.17072
2/2/2021 12:24,-22.58029,0,7.204865,9.809029
2/2/2021 12:25,-25.03979,0,6.192131,8.515984
2/2/2021 12:26,-27.01099,0,4.817711,7.575592
2/2/2021 12:27,-29.67846,0,4.085289,6.445313
2/2/2021 12:28,-31.88477,0,3.072556,5.712891
2/2/2021 12:29,-33.65704,0,2.765121,5.387367
2/2/2021 12:30,-35.41124,0,2.48481,4.636864
---------------------------------------------,,,,

虽然删除前五行并将第六行提升为 header,但这是一个快速修复;如果你想保留最顶层的信息,你需要合并这六行,然后提升它们。

  • 转置 table
  • 合并前六列,使用<linefeed>作为分隔符
  • 转置 table
  • 将第一行提升为 headers
  • 键入它(可以由 UI 自动完成)
  • 务必(在 Excel 中)启用 自动换行 并正确调整 rows/columns 大小。

这种方法的缺点是第一行会有很多信息,而不是分成几行

M代码

let
    Source = Csv.Document(File.Contents("C:\Users\ron\Desktop\sampledata.csv"),[Delimiter=",", Columns=5, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Transposed Table" = Table.Transpose(Source),
    #"Merged Columns" = Table.CombineColumns(#"Transposed Table",
        {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"},
        Combiner.CombineTextByDelimiter("#(lf)", QuoteStyle.None),"Merged"),
    #"Transposed Table1" = Table.Transpose(#"Merged Columns"),

    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{
        {"Time of Export: 2021-03-30 1:10:00#(lf)Start Date / Time: 2021-03-30 12:00:00#(lf)End Date / Time: 2021-03-30 12:30:00#(lf)Sample Rate: 1 minute(s)#(lf)#(lf)TimeStamp", type datetime}, 
        {"#(lf)#(lf)#(lf)#(lf)Temperature Probe 1#(lf)TP 1001 temperature (ï½°C)", type number}, 
        {"#(lf)#(lf)#(lf)#(lf)Temperature Probe 2#(lf)TP 1002 temperature (ï½°C)", Int64.Type},
         {"#(lf)#(lf)#(lf)#(lf)Temperature Probe 3#(lf)TP 1003 temperature (ï½°C)", type number}, 
         {"#(lf)#(lf)#(lf)#(lf)Temperature Probe 4#(lf)TP 1004 temperature (ï½°C)", type number}})
in
    #"Changed Type"

来自您的数据的结果

要绘制的值现在是数字