【问题标题】:TDMS file read data in pythonTDMS文件在python中读取数据
【发布时间】:2020-07-24 05:50:16
【问题描述】:

在项目期间,我不得不处理一个 TDMS 文件。 我问是因为无法立即读取文件。

我的目标:通过将 TDMS 文件转换为 DataFrame 格式进行分析

第一次尝试, - 使用 npTdms 包执行 TdmsFile 打开。 - 转换为 read_data() 执行 pd.DataFrame 命令。

from nptdms import TdmsFile, TdmsWriter, ChannelObject, GroupObject
filenameS = "ex.tdms"
tdms_file = TdmsFile(filenameS)

[enter image description here][1]

所以我使用 TdmsFile.open() 命令成功加载。

但我在第二次尝试时尝试了 read_data() 并检查了错误。

csv_merge = pd.DataFrame()
for i in tdms_file.group_channels('Analog Data'):
temp = i.read_data()
csv_merge = pd.concat([csv_merge, pd.DataFrame({i.channel: temp})], axis=1)

enter image description here

最后一次尝试

tdms_file = TdmsFile.open(filenameS)
df = tdms_file.as_dataframe()

enter image description here

【问题讨论】:

  • 你能把链接发到你的 tdms 文件吗?
  • 发送了一个 Google Drive 链接,下载了吗?

标签: python readlines read-data


【解决方案1】:

给你=^..^=

from nptdms import TdmsFile
import pandas as pd

# load file
tdms_file = TdmsFile('20200609_130131.69.tdms')
# show groups
groups_data = tdms_file.groups()
print(groups_data)
# show channels
channels_data = tdms_file['group name'].channels()
print(channels_data)
# show data in channel
selected_data = tdms_file['group name']['channel name']
print(selected_data.data)

# load into df
df = pd.DataFrame(data=selected_data.data)

df 输出:

0  0.000000
1  0.111111
2  0.222222
3  0.333333
4  0.444444
5  0.555556
6  0.666667
7  0.777778
8  0.888889
9  1.000000

【讨论】:

  • 我刚打开脚本,出现错误。我在答案中输入了错误代码。你能确认一下吗?
  • @Okgukui 我不知道文件中包含哪些组名和频道,我只是使用默认值。
  • @Okgukui 如果您能接受我的回答并为此投票,那就太好了:)
【解决方案2】:

我不知道..

所以,我是使用 TdmsFile.open() 命令完成的。然后出现错误

【讨论】:

    猜你喜欢
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多