'For loop not functioning while extracting data from .asd file

I have several .asd files for range of RPM from 0-5000. Each file has 6 columns ('BasePlate','MidFoil_SE','F1_SE','F1_SW','F1_NW','F1_NE') plus a time column. I want to extract each of these 6 column data for each RPM and put all data of each column into one csv file.

My code is as follows:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

x = 'm0-Top-RPM_0_001.asd'
df = pd.read_csv(x, skiprows=12, delimiter=";", dtype=float, na_values=["-∞", "∞"],)  
df.columns = ['Time (s)','BasePlate','MidFoil_SE','F1_SE','F1_SW','F1_NW','F1_NE']

Fs = 500000 # used 500 kHz
time = df['Time (s)'].astype('float')


columns = ['BP', 'MF', 'F1SE', 'F1SW', 'F1NW', 'F1NE']


for sig, col in zip(df.columns[1:7], columns):
    signal = df[sig]
    plt.plot(time, signal, 'b', linewidth='0.5')
    plt.title(col + '_{}'.format(x[:4]))
    plt.xlabel('Time [s]')
    plt.ylabel('Amplitude')
    plt.show()
    
    # frequency axis
    n = len(time)
    n1 = int(n/2)
    fr = (Fs/2)*np.linspace(0,2,num=n1) # gives t/2 number of samples between 8 and 10    
    
    # Computing FFT
    X = np.fft.fft(signal)
    X_m = (2/n)*abs(X[0:len(fr)])
    
    plt.plot(abs(X))
    plt.title('Full Spectrum_' + str(col) + '{}'.format(x[:4]))
    plt.xlabel('Frequency [Hz]')
    plt.ylabel('Amplitude [V]')
    plt.show()

    plt.plot(fr[0:1500], X_m[0:1500])
    plt.title('Absolute Frequency Spectrum_' + str(col) + '{}'.format(x[:4]))
    plt.xlabel('Frequency [Hz]')
    plt.ylabel('Amplitude [V]')
    plt.rcParams["figure.dpi"] = 350
    plt.show()
    
    df = pd.DataFrame()
    df['Frequency'] = fr[0:1500]
    df['PSD'] = X_m[0:1500]
    df.to_csv("PSDvalues.csv",)   

I get the error: raise KeyError(key) from err. KeyError: 'MidFoil_SE'. I know that this code means MidFoil_SE does not exist but it does and I don't know why this error shows. So, I get only the result for BasePlate and then the error shows. Could someone help point out the issue ? The file can be found here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source