用python pandas读取LabVIEW TDMS文件

Sun*_*r N 1 labview python-3.x pandas

如何使用python读取标准labVIEW生成的TDMS文件?

Sun*_*r N 5

为了社区的利益,发布示例代码库我用来有效地将 *.tdms 文件读入 Pandas 数据帧。经过多次试验,简化了代码以方便使用和记录。

#import required libraries
from nptdms import TdmsFile
import numpy as np
import pandas as pd

#bokeh plots
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook

#load the tdms file
tdms_file = TdmsFile("/Volumes/Data/dummy/sample.tdms")

#split all the tdms grouped channels to a separate dataframe

#tdms_file.as_dataframe()
for group in tdms_file.groups():
    grp1_data = tdms_file.object('grp1').as_dataframe()
    grp2_data = tdms_file.object('grp2').as_dataframe()

#plot the data on bokeh plots
# Use Bokeh chart to make plot
p = bokeh.charts.Line(grp1_data, x='time', y='values', color='parameter', xlabel='time (h)', ylabel='values')

# Display it
bokeh.io.show(p)
Run Code Online (Sandbox Code Playgroud)

欢迎提出建议和改进。