如何修复使用pandas和jupyter笔记本时的缩进错误?

2024-06-28 15:17:50 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我尝试过的代码,并且我已经发布了我得到的错误。请帮忙

 X_all.HM1 = X_all.HM1.astype('str')
 X_all.HM2 = X_all.HM2.astype('str')
                X_all.HM3 = X_all.HM3.astype('str')
                X_all.AM1 = X_all.AM1.astype('str')
                X_all.AM2 = X_all.AM2.astype('str')
                X_all.AM3 = X_all.AM3.astype('str')

def preprocess_features(X):
                    output = pd.DataFrame(index = X.index)

                    for col, col_df in X.iteritems():

             if col_df.dtype == object:
                        col_df = pd.get_dummies(col_df, prefix = col)

                       output = output.join(col_df)

                         return output

            X_all = preprocess_features(X_all)
            print "Processed feature columns ({} total features):\n{}".format(len(X_all.columns), list(X_all.columns))

            print "\nFeature values:"
            display (X_all)`

这就是我犯的错误 文件“”,第37行 如果列_数据框类型==对象:


Tags: columnsdfoutput错误colallfeaturesstr