Beckhoff TwinCat Scope CSV格式转换为 pandas 数据框 [英] Beckhoff TwinCat Scope CSV Format into pandas dataframe

查看:307
本文介绍了Beckhoff TwinCat Scope CSV格式转换为 pandas 数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Beckhoff TwinCAT Scope中记录数据后,可以将这些数据导出到CSV文件。然而,所述CSV文件具有相当复杂的格式。有人可以建议将这种文件导入pandas Dataframe以便进行分析的最有效方法吗?

After recording data in Beckhoff TwinCAT Scope, one can export this data to a CSV file. Said CSV file, however, has a rather complicated format. Can anyone suggestion the most effective way to import such a file into a pandas Dataframe so I can perform analysis?

可以在此处找到格式示例:
> https:/ /infosys.beckhoff.com/english.php?content=../content/1033/tcscope2/html/TwinCATScopeView2_Tutorial_SaveExport.htm&id=

An example of the format can be found here: https://infosys.beckhoff.com/english.php?content=../content/1033/tcscope2/html/TwinCATScopeView2_Tutorial_SaveExport.htm&id=

推荐答案

无需编写自定义解析器。使用示例数据 scope_data.csv

No need to write a custom parser. Using the example data scope_data.csv:

Name,fasd,,,,
File,C;\,,,,
Start,dfsd,,,,
,,,,,
,,,,,
Name,Peak,Name,PULS1,Name,SINUS_FAST
Net id,123.123.123,Net id,123.123.124,Net Id,123.123.125
Port,801,Port,801,Port,801
,,,,,
0,0.6113936598,0,0.07994111349,0,0.08425652468
0,0.524852539,0,0.2051963401,0,0.4391185847
0,0.4993723482,0,0.2917317117,0,0.4583736263
0,0.5976553194,0,0.8675482865,0,0.8435987898
0,0.06087224998,0,0.7933980583,0,0.5614294705
0,0.1967968423,0,0.3923966599,0,0.1951608414
0,0.9723649064,0,0.5187276782,0,0.7646786192

您可以按以下方式导入:

You can import as follows:

import pandas as pd

scope_data = pd.read_csv(
    "scope_data.csv",
    skiprows=[*range(5), *range(6, 9)],
    usecols=[*range(1, 6, 2)]
)

然后您得到

>>> scope_data.head()
       Peak     PULS1  SINUS_FAST
0  0.611394  0.079941    0.084257
1  0.524853  0.205196    0.439119
2  0.499372  0.291732    0.458374
3  0.597655  0.867548    0.843599
4  0.060872  0.793398    0.561429

我没有原始范围csv,但是对<$ c $做了一点调整c> skiprows 和 use_cols 应该会给您想要的结果。

I don't have the original scope csv, but a little adjustment of skiprows and use_cols should give you the desired result.

这篇关于Beckhoff TwinCat Scope CSV格式转换为 pandas 数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆