SintaxError,for循环中的无效Sintax

时间:2019-07-19 14:38:18

标签: python pandas for-loop syntax-error

我对for循环有疑问。我不明白为什么。该错误在第18行的for循环中提及。以下代码:

b1_1_acc=pd.DataFrame([])
acc_cols=['Hour','Minute','Second','mu_second','Horiz_acc','Vert_acc']
### Set your path to the folder containing the .csv files
PATH = 'C:\\Users\\UserName\\Documents\\python\\NASA\\FEMTOBearingDataSet\\Training_set\\Bearing1_1\\acc\\' # Use your path

### Fetch all files in path
fileNames = os.listdir(PATH)

### Filter file name list for files ending with .csv
fileNames = [file for file in fileNames if '.csv' in file]

### Loop over all files
for file in fileNames:

    ### Read .csv file and append to list
    df = pd.read_csv(PATH + file, sep=',', header=None, names=acc_cols, index_col = None)
    b1_1_acc = b1_1_acc.append({
        row for row in range(0,len(df)):
            'Horiz_Line_Integral':np.sum(abs(df['Horiz_acc'][row+1]-df['Horiz_acc'][row])),
        #'Horiz_Mean':df['Horiz_acc'].mean(), 
        #'Horiz_Max':df['Horiz_acc'].max(), 
        #'Horiz_Min':df['Horiz_acc'].min(),
        #'Horiz_RMS':np.sqrt(np.mean(df['Horiz_acc']**2)),
        #'Horiz_kurtosis':kurtosis(df['Horiz_acc']),
        #'Horiz_skewness':skew(df['Horiz_acc']),
        #'Horiz_Entropy':-np.sum((df['Horiz_acc']/sum(df['Horiz_acc']))*np.log2(df['Horiz_acc'])),
        #'Horiz_energy':np.sum(df['Horiz_acc']**2),
        #'Vert_Mean':df['Vert_acc'].mean(), 
        #'Vert_Max':df['Vert_acc'].max(), 
        #'Vert_Min':df['Vert_acc'].min(),
        #'Vert_RMS':np.sqrt(np.mean(df['Vert_acc']**2)),
        #'Vert_kurtosis':kurtosis(df['Vert_acc']),
        #'Vert_skewness':skew(df['Vert_acc']),
        #'Vert_Entropy':-np.sum((df['Vert_acc']/sum(df['Vert_acc']))*np.log2(df['Vert_acc'])),
        #'Vert_energy':np.sum(df['Vert_acc']**2),
        #'Info_Gain':info_gain.info_gain(df['Horiz_acc'],df['Vert_acc'])
        }, ignore_index=True)

b1_1_acc.head()

这是python向我显示的错误:

File "<ipython-input-28-07d34b6f5c93>", line 18
    row for row in range(0,len(df)):
                                   ^
SyntaxError: invalid syntax

如果我将第18行更改为此:

for row in range(0,len(df)):
            'Horiz_Line_Integral':np.sum(abs(df['Horiz_acc'][row+1]-df['Horiz_acc'][row])),

我收到以下错误:

 File "<ipython-input-31-0f8d7a8efa8c>", line 18
    for row in range(0,len(df)):
      ^
SyntaxError: invalid syntax

你能帮我吗?谢谢!

0 个答案:

没有答案