我有几列长短不一的数据y_train,y_pred1,z_train,y_test,y_pred2,z_test,怎么放到一张表格中pandas
时间: 2023-12-24 13:54:20 浏览: 41
您可以使用pandas的DataFrame函数将这些数据组合到一张表格中。首先,你需要将这些数据存储在pandas的Series对象中,然后将它们传递给DataFrame函数。下面是一个示例代码:
```python
import pandas as pd
# 将数据存储在Series对象中
y_train = pd.Series([1, 2, 3])
y_pred1 = pd.Series([1.1, 2.2, 3.3])
z_train = pd.Series(['A', 'B', 'C'])
y_test = pd.Series([4, 5, 6])
y_pred2 = pd.Series([4.4, 5.5, 6.6])
z_test = pd.Series(['D', 'E', 'F'])
# 将Series对象传递给DataFrame函数
df = pd.DataFrame({'y_train': y_train, 'y_pred1': y_pred1, 'z_train': z_train, 'y_test': y_test, 'y_pred2': y_pred2, 'z_test': z_test})
# 显示DataFrame
print(df)
```
输出结果应该如下所示:
```
y_train y_pred1 z_train y_test y_pred2 z_test
0 1 1.1 A 4 4.4 D
1 2 2.2 B 5 5.5 E
2 3 3.3 C 6 6.6 F
```
这样,你就将这些数据整合到了一张表格中。希望对你有所帮助!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)