Python 熊猫:属性错误:';dict';对象没有属性';转换';

Python 熊猫:属性错误:';dict';对象没有属性';转换';,python,python-3.x,pandas,Python,Python 3.x,Pandas,我对python和pandas很陌生,但我遇到了一个错误。我正在处理音频文件,我需要从音频流中提取一些功能 def load_features(self, audio_file): def stereo_to_mono(x): # stereo to mono if len(x.shape) > 1 and x.shape[1] > 1: print('Converting stereo to mono')

我对python和pandas很陌生,但我遇到了一个错误。我正在处理音频文件,我需要从音频流中提取一些功能

def load_features(self, audio_file):
    def stereo_to_mono(x):
        # stereo to mono
        if len(x.shape) > 1 and x.shape[1] > 1:
            print('Converting stereo to mono')
            x = x.mean(axis=1)
        return x

    def cut_or_pad_to_length(x, duration, fs):
        desired_length = int(round(duration * fs))
        length = len(x)
        diff = length - desired_length
        abs_diff = abs(diff)
        if diff < 0:
            print('Padding')
            # put the short signal in the middle
            pad_before = abs_diff // 2
            pad_after = abs_diff - pad_before
            x = np.lib.pad(x, (pad_before, pad_after), 'constant')
        elif diff > 1:
            print('Cutting')
            # cut the beginning
            x = x[0:desired_length]
        return x

    def adjust_input(x, fs):
        x = stereo_to_mono(x)
        x = cut_or_pad_to_length(x, 2.0, fs)
        return x

    #x is data, fs is samplerate
    x, fs = sf.read(audio_file)
    x0 = adjust_input(x, fs)

    # pitchgram
    x_features = self.ch.transform(x0)

    if self.scaler is not None:
        x_features = self.scaler.transform(x_features.reshape(1, -1)) \

    # 1 data point with 2D features
    x_features = x_features.reshape(1, *x_features.shape)

    return x_features

    def predict_class_label(self, audio_file):
    x_features = self.load_features(audio_file)
    instrument_class = np_utils.probas_to_classes(self.model.predict(x_features, verbose=0))[0]
    label = self.instr_family_le.inverse_transform(instrument_class)
    return label

但是
x
x0
看起来不像字典,因为我像列表一样使用它们,但是转换给了我那个错误。。。还是我错了?很长一段时间都无法理解。

大概是
self.ch
dict
self.ch
dict
,但显然应该是
pd.DataFrame
在我看来并不是一个简单的例子。我想你可以试着减少它。用debug跟踪它,或者添加
print(type(__;))
你会找到解决方案
     File "C:/dipl0m/ml-master/instrument-classification/predict.py", line 104, in predict_probabilities
x_features = self.load_features(audio_file)
     File "C:/dipl0m/ml-master/instrument-classification/predict.py", line 87, in load_features
x_features = self.ch.transform(x0)
     AttributeError: 'dict' object has no attribute 'transform'