代码#合并训练数据和测试数据 datal = pd.concat([data_train ,data_test],axis =0) #处理 data _ received 属性、 date 属性 data1['date_received ']=data1['date_received'].astype('str'). apply ( lambda x : x . split ('.')[0]) datal [' date_received ']= pd . to_datetime (data1[' date_received ']) datal [' date ']= datal (' date '). astype (' str '). apply ( lambda x : x . split ('.')[0]) datal [' date ']= pd . to_datetime ( datal [' date '])报错name 'data1' is not defined解决
时间: 2023-07-16 21:17:39 浏览: 399
在代码中,第二行中的`data1`没有被定义,因此会报错。可以将第二行的`data1`改为`datal`,因为上一行已经定义了`datal`作为合并后的数据集。修改后的代码如下:
```python
# 合并训练数据和测试数据
datal = pd.concat([data_train, data_test], axis=0)
# 处理 data_received 属性、date属性
datal['date_received'] = datal['date_received'].astype('str').apply(
lambda x: x.split('.')[0])
datal['date_received'] = pd.to_datetime(datal['date_received'])
datal['date'] = datal['date'].astype('str').apply(
lambda x: x.split('.')[0])
datal['date'] = pd.to_datetime(datal['date'])
```
阅读全文