如何计算包含字符串的列的频谱图?

How do I calculate the spectogram of a a column which contains strings?

我一直在尝试计算 excel 文件的输出电压值的频谱图,其中所有值都自动存储在第一列中,看起来像这样:

#CHANNEL:CH1
#CLOCK=200uS
#SIZE=130048
#UNITS:V

0.6902
0.7216
0.6902
0.6902
0.7216
0.7216
0.6902
0.6902
0.7216
0.6902
0.7216
0.6902
0.7216
0.7216
0.6902
0.6902
0.6902
0.6902
0.6902
0.6902
0.7216
0.7216
0.6902
...

所以当我尝试下面的代码时

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import signal

data = pd.read_excel(r'/home/mirofeliciano/oscilo/test.xlsx')

x = np.array(data["#CHANNEL:CH1"])

voltage = x[4:]

fs = 0.05

period= 20

f, t, Sxx = signal.spectrogram(voltage, fs)

plt.pcolormesh(t, f, Sxx, shading='gouraud')

plt.ylabel('Frequency [Hz]')

plt.xlabel('Time [sec]')

plt.show()

它给出错误:

TypeError: Image data of dtype object cannot be converted to float

确实,当我查看电压矢量时说

In [2]: voltage
Out[2]: array([0.6902, 0.7216, 0.6902, ..., 0.6902, 0.6902, 0.7216], dtype=object)

因此,即使我将向量剪切为不包含前几行字符串,它仍然将其视为一个对象。所以我的问题是如何以仅考虑数字的方式仅获取值。

您可以像这样转换 voltage 中的条目:

f, t, Sxx = signal.spectrogram(voltage.astype(float), fs)