请提供帮助。你能告诉我我定义的格式有什么问题吗?
from sklearn.ensemble import GradientBoostingRegressor
df = pd.read_csv('timeseries.csv')
df.head()
df['timestamp'] = pd.to_datetime(df['timestamp'], format='%Y-%m-%d %H:%M:%S.%f%Z')
X = df['timestamp']
y = df['time_minutes']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
reg = GradientBoostingRegressor(random_state=0)
reg.fit(X_train, y_train)
GradientBoostingRegressor(random_state=0)
reg.predict(X_test[1:2])
reg.score(X_test, y_test)
ValueError:时间数据"2021-07-19 11:48:03.357+00"与格式"%Y-%m-%d%H:%m:%S"不匹配。%f%Z'(匹配(
panda在加载csv文件时应该很容易处理这一问题,以后不需要解析:
df = pd.read_csv('timeseries.csv', parse_dates=True)