【问题标题】:how can i fix the 'syntax error' in python using jupyter notebook?如何使用 jupyter notebook 修复 python 中的“语法错误”?
【发布时间】:2019-09-01 22:42:30
【问题描述】:

你好试图修复错误,但我不能,我不知道我哪里出错了,任何人都可以帮忙。下面是我的代码

我之前的错误是缩进错误

import pandas as pd 
import numpy as np
import xgboost as xgb
import sklearn as s 
import matplotlib 
import tensorflow as tf 
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from IPython.display import display 
df = pd.read_csv("C:/Users/patel/Desktop/tap.csv")
from IPython.display import display
X_all = df.drop(['FTR'],1)
y_all = df['FTR']

# Standardising the data.
from sklearn.preprocessing import scale

#Center to the mean and component wise scale to unit variance.
cols = [['FTHG','FTAG','HTHG','HTAG']]
for col in cols:
    X_all[col] = scale(X_all[col])
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)

文件“”,第 39 行 print "已处理的特征列 ({} 总特征):\n{}".format(len(X_all.columns), list(X_all.columns)) ^ SyntaxError: 无效语法

【问题讨论】:

  • 你用的是什么版本的 Python?
  • 嗨@Shuvojit 我正在使用最新版本的python,即3

标签: python pandas machine-learning scikit-learn


【解决方案1】:

如果您使用的是 Python 3,则 print 函数中的括号会丢失。以下代码应该可以工作。

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

【讨论】:

  • 但是现在我在修复后出现数据帧错误,我不知道为什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-17
  • 2021-07-24
  • 2019-08-31
  • 1970-01-01
  • 2021-09-06
相关资源
最近更新 更多