首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何组合dates和true_predictions来创建一个DataFrame?

要组合dates和true_predictions来创建一个DataFrame,可以使用pandas库中的DataFrame函数。首先,导入pandas库:

代码语言:txt
复制
import pandas as pd

然后,将dates和true_predictions作为字典的键值对传递给DataFrame函数,其中dates作为"dates"列,true_predictions作为"true_predictions"列。示例代码如下:

代码语言:txt
复制
dates = ['2022-01-01', '2022-01-02', '2022-01-03']
true_predictions = [10, 15, 20]

df = pd.DataFrame({'dates': dates, 'true_predictions': true_predictions})

这样就创建了一个名为df的DataFrame,其中包含两列:"dates"和"true_predictions"。可以通过打印df来查看DataFrame的内容:

代码语言:txt
复制
print(df)

输出结果如下:

代码语言:txt
复制
        dates  true_predictions
0  2022-01-01                10
1  2022-01-02                15
2  2022-01-03                20

这样就成功地将dates和true_predictions组合成了一个DataFrame。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券