ValueError: time data '2021-07-19 11:48:03.357+00' does not match format '%Y-%m-%d %H:%M:%S.%f%Z' (match)
ValueError: time data '2021-07-19 11:48:03.357+00' does not match format '%Y-%m-%d %H:%M:%S.%f%Z' (match)
请帮忙。你能告诉我我定义的格式有什么问题吗?
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: time data '2021-07-19 11:48:03.357+00' does not match format '%Y-%m-%d %H:%M:%S.%f%Z' (match)
pandas 应该在您加载 csv 文件时轻松处理,您以后不需要解析它:
df = pd.read_csv('timeseries.csv', parse_dates=True)
请帮忙。你能告诉我我定义的格式有什么问题吗?
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: time data '2021-07-19 11:48:03.357+00' does not match format '%Y-%m-%d %H:%M:%S.%f%Z' (match)
pandas 应该在您加载 csv 文件时轻松处理,您以后不需要解析它:
df = pd.read_csv('timeseries.csv', parse_dates=True)